Author: jcouteau Date: 2013-06-21 22:02:35 +0200 (Fri, 21 Jun 2013) New Revision: 345 Url: http://chorem.org/projects/chorem/repository/revisions/345 Log: #refs #931 : Add a Cancelled extension. - Quotation can now get the Cancelled extension in sales funnel. - Quotation status change in Sales funnel now gets a popup to precise values - Still needs to update sales funnel amounts when using cancelled extension Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/FunnelAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesAction.java trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp trunk/chorem-webmotion/src/main/webapp/js/chorem.js Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/FunnelAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/FunnelAction.java 2013-06-20 14:35:02 UTC (rev 344) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/FunnelAction.java 2013-06-21 20:02:35 UTC (rev 345) @@ -1,11 +1,7 @@ package org.chorem.webmotion.actions.sales; import org.chorem.ChoremClient; -import org.chorem.entities.Accepted; -import org.chorem.entities.Draft; -import org.chorem.entities.Quotation; -import org.chorem.entities.Rejected; -import org.chorem.entities.Sent; +import org.chorem.entities.*; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.query.WikittyQuery; @@ -29,6 +25,7 @@ WikittyQuery leadQuotationQuery = new WikittyQueryMaker().and() .exteq(Quotation.EXT_QUOTATION) .extne(Draft.EXT_DRAFT) + .extne(Cancelled.EXT_CANCELLED) .end().setLimit(WikittyQuery.MAX); WikittyQueryResult<Quotation> leads = @@ -46,6 +43,7 @@ WikittyQuery draftQuotationQuery = new WikittyQueryMaker().and() .exteq(Draft.EXT_DRAFT) .extne(Sent.EXT_SENT) + .extne(Cancelled.EXT_CANCELLED) .end().setLimit(WikittyQuery.MAX); WikittyQueryResult<Quotation> drafts = @@ -64,6 +62,7 @@ .exteq(Sent.EXT_SENT) .extne(Accepted.EXT_ACCEPTED) .extne(Rejected.EXT_REJECTED) + .extne(Cancelled.EXT_CANCELLED) .end().setLimit(WikittyQuery.MAX); WikittyQueryResult<Quotation> sents = Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesAction.java 2013-06-20 14:35:02 UTC (rev 344) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/sales/SalesAction.java 2013-06-21 20:02:35 UTC (rev 345) @@ -23,16 +23,21 @@ * #L% */ +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.ChoremClient; import org.chorem.entities.Accepted; import org.chorem.entities.Draft; import org.chorem.entities.Rejected; import org.chorem.entities.Sent; import org.chorem.entities.Started; +import org.chorem.entities.Cancelled; import org.chorem.webmotion.render.RenderWikittyJson; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; +import org.nuiton.wikitty.WikittyUtil; +import java.text.ParseException; import java.util.Date; /** @@ -45,23 +50,40 @@ */ public class SalesAction extends WebMotionController { - public Render send(ChoremClient client, String id) { + static private Log log = LogFactory.getLog(SalesAction.class); + + public Render send(ChoremClient client, String id, String sendingDate) { Sent sent = client.restore(Sent.class, id); - sent.setPostedDate(new Date()); + try { + sent.setPostedDate(WikittyUtil.parseDate(sendingDate)); + } catch (ParseException e) { + log.debug("Could not parse date : " + sendingDate); + getContext().addInfoMessage("message", "Warning: Could not parse date " + sendingDate); + } sent = client.store(sent); return new RenderWikittyJson(sent); } - public Render accept(ChoremClient client, String id) { + public Render accept(ChoremClient client, String id, String acceptedDate) { Accepted accepted = client.restore(Accepted.class, id); - accepted.setAcceptedDate(new Date()); + try { + accepted.setAcceptedDate(WikittyUtil.parseDate(acceptedDate)); + } catch (ParseException e) { + log.debug("Could not parse date : " + acceptedDate); + getContext().addInfoMessage("message", "Warning: Could not parse date " + acceptedDate); + } client.store(accepted); return new RenderWikittyJson(accepted); } - public Render reject(ChoremClient client, String id) { + public Render reject(ChoremClient client, String id, String rejectedDate) { Rejected rejected = client.restore(Rejected.class, id); - rejected.setRejectedDate(new Date()); + try { + rejected.setRejectedDate(WikittyUtil.parseDate(rejectedDate)); + } catch (ParseException e) { + log.debug("Could not parse date : " + rejectedDate); + getContext().addInfoMessage("message", "Warning: Could not parse date " + rejectedDate); + } client.store(rejected); return new RenderWikittyJson(rejected); } @@ -73,9 +95,31 @@ return new RenderWikittyJson(started); } - public Render answer(ChoremClient client, String id) { + public Render answer(ChoremClient client, String id, String sendingDate, + String reference) { Draft draft = client.restore(Draft.class, id,".*"); + try { + draft.setSendingDate(WikittyUtil.parseDate(sendingDate)); + } catch (ParseException e) { + log.debug("Could not parse date : " + sendingDate); + getContext().addInfoMessage("message", "Warning: Could not parse date " + sendingDate); + } + draft.setReference(reference); draft = client.store(draft); return new RenderWikittyJson(draft); } + + public Render cancel(ChoremClient client, String id, String cancelledDate, + String reason) { + Cancelled cancelled = client.restore(Cancelled.class, id, ".*"); + try { + cancelled.setCancelledDate(WikittyUtil.parseDate(cancelledDate)); + } catch (ParseException e) { + log.debug("Could not parse date : " + cancelledDate); + getContext().addInfoMessage("message", "Warning: Could not parse date " + cancelledDate); + } + cancelled.setReason(reason); + cancelled = client.store(cancelled); + return new RenderWikittyJson(cancelled); + } } Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp 2013-06-20 14:35:02 UTC (rev 344) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp 2013-06-21 20:02:35 UTC (rev 345) @@ -72,6 +72,7 @@ </p> </div> <a class="btn btn-success pull-right salesFunnelItemButton lead" wikittyId="${q.wikittyId}">Répondre</a> + <a class="btn btn-warning pull-right salesFunnelItemButton toCancelled" wikittyId="${q.wikittyId}">Annuler</a> <div class="pull-right salesFunnelItemPrice"> <p class="salesFunnelItemTitle"> <w:display wikitty="${q.wikitty}" fqfield="Quotation.amount" label=""/> @@ -99,6 +100,7 @@ <p><span class="salesFunnelItemTitle"><a class="name-link" href="<c:url value="/wikitty/Project/view/${q.project}"/>"><w:display wikitty="${q.wikitty}" fqfield="Quotation.project" label=""/></a></span> - <small><w:display wikitty="${q.wikitty}" fqfield="Quotation.description" label=""/></small></p> </div> <a class="btn btn-success pull-right salesFunnelItemButton draft" wikittyId="${q.wikittyId}">Envoyer</a> + <a class="btn btn-warning pull-right salesFunnelItemButton toCancelled" wikittyId="${q.wikittyId}">Annuler</a> <div class="pull-right salesFunnelItemPrice"> <p class="salesFunnelItemTitle"><w:display wikitty="${q.wikitty}" fqfield="Quotation.amount" label=""/></p> <small><w:display wikitty="${q.wikitty}" fqfield="Quotation.category" label=""/> - <w:display wikitty="${q.wikitty}" fqfield="Quotation.estimatedDays" label=""/>j - <w:display wikitty="${q.wikitty}" fqfield="Quotation.conversionHope" label=""/></small> @@ -122,6 +124,7 @@ </div> <a class="btn btn-success pull-right salesFunnelItemButton sent toAccepted" wikittyId="${q.wikittyId}">Accepté</a> <a class="btn btn-danger pull-right salesFunnelItemButton sent toRejected" wikittyId="${q.wikittyId}">Rejeté</a> + <a class="btn btn-warning pull-right salesFunnelItemButton toCancelled" wikittyId="${q.wikittyId}">Annuler</a> <div class="pull-right salesFunnelItemPrice"> <p class="salesFunnelItemTitle"><w:display wikitty="${q.wikitty}" fqfield="Quotation.amount" label=""/></p> <small><w:display wikitty="${q.wikitty}" fqfield="Quotation.category" label=""/> - <w:display wikitty="${q.wikitty}" fqfield="Quotation.estimatedDays" label=""/>j - <w:display wikitty="${q.wikitty}" fqfield="Quotation.conversionHope" label=""/></small> @@ -132,6 +135,60 @@ </ul> </div> + <div id="dialog-form-leadToDraft" title="Proposition commerciale à envoyer"> + <form> + <fieldset> + <label for="sendingDate">Date d'envoi</label> + <input type="text" name="sendingDate" id="sendingDate" class="datepicker" /> + <label for="reference">Référence</label> + <input type="text" name="reference" id="reference" value="" class="text ui-widget-content ui-corner-all" /> + <input type="hidden" name="id" id="lead-wikittyId"/> + </fieldset> + </form> + </div> + + <div id="dialog-form-draftToSent" title="Proposition commerciale envoyée"> + <form> + <fieldset> + <label for="sendDate">Date d'envoi</label> + <input type="text" name="sendDate" id="sendDate" class="datepicker" /> + <input type="hidden" name="id" id="draft-wikittyId"/> + </fieldset> + </form> + </div> + + <div id="dialog-form-sentToAccepted" title="Proposition commerciale acceptée"> + <form> + <fieldset> + <label for="acceptedDate">Date d'acceptation</label> + <input type="text" name="acceptedDate" id="acceptedDate" class="datepicker" /> + <input type="hidden" name="id" id="sent-wikittyId"/> + </fieldset> + </form> + </div> + + <div id="dialog-form-sentToRejected" title="Proposition commerciale refusée"> + <form> + <fieldset> + <label for="rejectedDate">Date de refus</label> + <input type="text" name="rejectedDate" id="rejectedDate" class="datepicker" /> + <input type="hidden" name="id" id="rejected-wikittyId"/> + </fieldset> + </form> + </div> + + <div id="dialog-form-toCancelled" title="Proposition commerciale annulée"> + <form> + <fieldset> + <label for="cancelledDate">Date d'annulation</label> + <input type="text" name="cancelledDate" id="cancelledDate" class="datepicker" /> + <label for="cancelledReason">Raison</label> + <input type="text" name="cancelledReason" id="cancelledReason" value="" class="text ui-widget-content ui-corner-all" /> + <input type="hidden" name="id" id="cancelled-wikittyId"/> + </fieldset> + </form> + </div> + </div> </div> Modified: trunk/chorem-webmotion/src/main/webapp/js/chorem.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/chorem.js 2013-06-20 14:35:02 UTC (rev 344) +++ trunk/chorem-webmotion/src/main/webapp/js/chorem.js 2013-06-21 20:02:35 UTC (rev 345) @@ -93,6 +93,44 @@ }); } }); + + +/*********** SALES FUNNEL FUNCTIONS**********************/ +function leadToDraft(){ + var id = $(this).attr('wikittyId'); + var oldQuotation = $(this).parent(); + $("#lead-wikittyId").val(id); + $("#dialog-form-leadToDraft" ).data("oldQuotation", oldQuotation).dialog( "open" ); +}; + +function draftToSent(){ + var id = $(this).attr('wikittyId'); + var oldQuotation = $(this).parent(); + $("#draft-wikittyId").val(id); + $("#dialog-form-draftToSent" ).data("oldQuotation", oldQuotation).dialog( "open" ); +}; + +function sentToAccepted(){ + var id = $(this).attr('wikittyId'); + var oldQuotation = $(this).parent(); + $("#sent-wikittyId").val(id); + $("#dialog-form-sentToAccepted" ).data("oldQuotation", oldQuotation).dialog( "open" ); +}; + +function sentToRejected(){ + var id = $(this).attr('wikittyId'); + var oldQuotation = $(this).parent(); + $("#rejected-wikittyId").val(id); + $("#dialog-form-sentToRejected" ).data("oldQuotation", oldQuotation).dialog( "open" ); +}; + +function toCancelled(){ + var id = $(this).attr('wikittyId'); + var oldQuotation = $(this).parent(); + $("#cancelled-wikittyId").val(id); + $("#dialog-form-toCancelled" ).data("oldQuotation", oldQuotation).dialog( "open" ); +}; + //ajout ble //clic sur les cases à cocher half-day d'une vacation (VacationRequest) @@ -106,7 +144,6 @@ dt.val(dtVal); } - $(document).ready(function() { $('.beginDateTR :checkbox').change(function(){ var dtetim = $(this).parent().parent().children('.beginDateTD').children('input'); @@ -233,260 +270,447 @@ // * SALES FUNNEL * // ******************************************************************** - function leadToDraft() { - var id = $(this).attr('wikittyId'); - var oldQuotation = $(this).parent(); - $.get(createUrl("/sales/funnel/json/answer/", id), - function(data){ - //success - var wikittyId = data.meta.id; - var wikitty = data.data; + + //Passage d'un lead -> draft + $("a.lead").click(leadToDraft); - var li = $("<li></li>").addClass("salesFunnelItem draft"); + $( "#dialog-form-leadToDraft" ).dialog({ + autoOpen: false, + height: 300, + width: 350, + modal: true, + buttons: { + Ok: function() { - //leftDiv - var leftDiv = $("<div></div>").addClass("pull-left"); - var aIconEdit = $("<a></a>") - .attr("href", createUrl("/wikitty/edit/", wikittyId)); - var iconEdit = $("<i></i>").addClass("icon-edit"); - aIconEdit.append(iconEdit); - leftDiv.append(aIconEdit); - var smallAccount = $("<small></small>"); - if (wikitty["Quotation.customer"]!=null){ - var customer = data.preloaded[wikitty["Quotation.customer"]]; - var firstName = customer.preloaded[customer.data["Employee.person"]].data["Person.firstName"]; - var lastName = customer.preloaded[customer.data["Employee.person"]].data["Person.lastName"]; - var company = customer.preloaded[customer.data["Employee.company"]].data["Company.name"]; - } - var aAccount = $("<a></a>") - .text(firstName + " " + lastName + " (" + company + ")") - .attr("href",createUrl("/wikitty/Employee/view/", wikitty["Quotation.customer"])); - smallAccount.append(aAccount); - leftDiv.append(smallAccount); - var leftP = $("<p> - </p>"); - var itemTitleSpan = $('<span></span>').addClass('salesFunnelItemTitle'); + var reference = $("#reference").val(); + var sendingDate = $("#sendingDate").val(); + var id = $("#lead-wikittyId").val(); + var oldQuotation = $(this).data('oldQuotation'); + var allFields = $([]).add($("#reference")).add($("#sendingDate")).add($("#lead-wikittyId")) - if (wikitty["Quotation.project"]!=null) { - var aProject = $("<a/>") - .addClass("nameLink") - .attr("href" , createUrl("/wikitty/Project/view/", wikitty["Quotation.project"])) - .text(data.preloaded[wikitty["Quotation.project"]].data["Project.name"]); - } - itemTitleSpan.append(aProject); - var descriptionSmall = $('<small/>').text(wikitty["Quotation.description"]); - leftP.append(descriptionSmall); - leftP.prepend(itemTitleSpan); - leftDiv.append(leftP); + var dialog = $( this ); - //button - var aSend = $('<a/>') - .attr('wikittyId', wikittyId) - .addClass("btn btn-success pull-right salesFunnelItemButton draft") - .text("Envoyer") - .click(draftToSent); + $.post(createUrl("/sales/funnel/json/answer/", id,"?sendingDate=", sendingDate, "&reference=",reference), + function(data){ + //success + var wikittyId = data.meta.id; + var wikitty = data.data; - //rightDiv - var rightDiv = $("<div>").addClass("pull-right"); - var rightP = $("<p>").addClass("salesFunnelItemTitle").text(wikitty["Quotation.amount"] +" €"); - if (wikitty["Quotation.category"] != null) { - var smallInfo = $("<small>") - .text(data.preloaded[wikitty["Quotation.category"]].data["WikittyTreeNode.name"] - + ' - ' + wikitty["Quotation.estimatedDays"] + 'j - ' + - wikitty["Quotation.conversionHope"] + "%"); - } - rightDiv.append(rightP); - rightDiv.append(smallInfo); + var li = $("<li></li>").addClass("salesFunnelItem draft"); - //clear:both - var clearBoth=$("<div style='clear:both;'/>") + //leftDiv + var leftDiv = $("<div></div>").addClass("pull-left"); + var aIconEdit = $("<a></a>") + .attr("href", createUrl("/wikitty/edit/", wikittyId)); + var iconEdit = $("<i></i>").addClass("icon-edit"); + aIconEdit.append(iconEdit); + leftDiv.append(aIconEdit); + var smallAccount = $("<small></small>"); + if (wikitty["Quotation.customer"]!=null){ + var customer = data.preloaded[wikitty["Quotation.customer"]]; + var firstName = customer.preloaded[customer.data["Employee.person"]].data["Person.firstName"]; + var lastName = customer.preloaded[customer.data["Employee.person"]].data["Person.lastName"]; + var company = customer.preloaded[customer.data["Employee.company"]].data["Company.name"]; + } + var aAccount = $("<a></a>") + .text(firstName + " " + lastName + " (" + company + ")") + .attr("href",createUrl("/wikitty/Employee/view/", wikitty["Quotation.customer"])); + smallAccount.append(aAccount); + leftDiv.append(smallAccount); + var leftP = $("<p> - </p>"); + var itemTitleSpan = $('<span></span>').addClass('salesFunnelItemTitle'); - li.append(leftDiv); - li.append(aSend); - li.append(rightDiv); - li.append(clearBoth); + if (wikitty["Quotation.project"]!=null) { + var aProject = $("<a/>") + .addClass("nameLink") + .attr("href" , createUrl("/wikitty/Project/view/", wikitty["Quotation.project"])) + .text(data.preloaded[wikitty["Quotation.project"]].data["Project.name"]); + } + itemTitleSpan.append(aProject); + var descriptionSmall = $('<small/>').text(wikitty["Quotation.description"]); + leftP.append(descriptionSmall); + leftP.prepend(itemTitleSpan); + leftDiv.append(leftP); - var drafts = $(".drafts"); - drafts.append(li); - oldQuotation.slideUp(); + //button + var aSend = $('<a/>') + .attr('wikittyId', wikittyId) + .addClass("btn btn-success pull-right salesFunnelItemButton draft") + .text("Envoyer") + .click(draftToSent); - //update draftAmount and draftAmountHope - var draftAmount = parseInt($("#draftAmount").text()) + wikitty["Quotation.amount"]; - var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; - var draftAmountHope = parseInt($("#draftAmountHope").text()) + amountHope; - $("#draftAmount").text(draftAmount); - $("#draftAmountHope").text(draftAmountHope); + var aCancelled = $('<a/>') + .attr('wikittyId', wikittyId) + .addClass("btn btn-warning pull-right salesFunnelItemButton toCancelled") + .text("Annuler") + .click(toCancelled); - //update leadAmount and leadAmountHope - var leadAmount = parseInt($("#leadAmount").text()) - wikitty["Quotation.amount"]; - var leadAmountHope = parseInt($("#leadAmountHope").text()) - amountHope; - $("#leadAmount").text(leadAmount); - $("#leadAmountHope").text(leadAmountHope); + //rightDiv + var rightDiv = $("<div>").addClass("pull-right"); + var rightP = $("<p>").addClass("salesFunnelItemTitle").text(wikitty["Quotation.amount"] +" €"); + if (wikitty["Quotation.category"] != null) { + var smallInfo = $("<small>") + .text(data.preloaded[wikitty["Quotation.category"]].data["WikittyTreeNode.name"] + + ' - ' + wikitty["Quotation.estimatedDays"] + 'j - ' + + wikitty["Quotation.conversionHope"] + "%"); + } + rightDiv.append(rightP); + rightDiv.append(smallInfo); - }).fail(function(){ - //fail - //TODO JC20130212 retour utilisateur - }); - } + //clear:both + var clearBoth=$("<div style='clear:both;'/>") - function draftToSent() { - var id = $(this).attr('wikittyId'); - var oldQuotation = $(this).parent(); - $.get(createUrl("/sales/funnel/json/send/", id), - function(data){ - //success + li.append(leftDiv); + li.append(aSend); + li.append(aCancelled); + li.append(rightDiv); + li.append(clearBoth); - var wikittyId = data.meta.id; - var wikitty = data.data; + var drafts = $(".drafts"); + drafts.append(li); + oldQuotation.slideUp(); - var li = $("<li></li>").addClass("salesFunnelItem draft"); + //update draftAmount and draftAmountHope + var draftAmount = parseInt($("#draftAmount").text()) + wikitty["Quotation.amount"]; + var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; + var draftAmountHope = parseInt($("#draftAmountHope").text()) + amountHope; + $("#draftAmount").text(draftAmount); + $("#draftAmountHope").text(draftAmountHope); - //leftDiv - var leftDiv = $("<div></div>").addClass("pull-left"); - var aIconEdit = $("<a></a>") - .attr("href",createUrl("/wikitty/edit/", wikittyId)); - var iconEdit = $("<i></i>").addClass("icon-edit"); - aIconEdit.append(iconEdit); - leftDiv.append(aIconEdit); - var smallAccount = $("<small></small>"); - if (wikitty["Quotation.customer"]!=null){ - var customer = data.preloaded[wikitty["Quotation.customer"]]; - var firstName = customer.preloaded[customer.data["Employee.person"]].data["Person.firstName"]; - var lastName = customer.preloaded[customer.data["Employee.person"]].data["Person.lastName"]; - var company = customer.preloaded[customer.data["Employee.company"]].data["Company.name"]; - } - var aAccount = $("<a></a>") - .text(firstName + " " + lastName + " (" + company + ")") - .attr("href", createUrl("/wikitty/Employee/view/", wikitty["Quotation.customer"])); - smallAccount.append(aAccount); - leftDiv.append(smallAccount); - var leftP = $("<p> - </p>"); - var itemTitleSpan = $('<span></span>').addClass('salesFunnelItemTitle'); + //update leadAmount and leadAmountHope + var leadAmount = parseInt($("#leadAmount").text()) - wikitty["Quotation.amount"]; + var leadAmountHope = parseInt($("#leadAmountHope").text()) - amountHope; + $("#leadAmount").text(leadAmount); + $("#leadAmountHope").text(leadAmountHope); - if (wikitty["Quotation.project"]!=null) { - var aProject = $("<a/>") - .addClass("nameLink") - .attr("href" , createUrl("/wikitty/Project/view/", wikitty["Quotation.project"])) - .text(data.preloaded[wikitty["Quotation.project"]].data["Project.name"]); - } - itemTitleSpan.append(aProject); - var descriptionSmall = $('<small/>').text(wikitty["Quotation.description"]); - leftP.append(descriptionSmall); - leftP.prepend(itemTitleSpan); - leftDiv.append(leftP); + allFields.val(""); - //button - var aAccepted = $('<a/>') - .attr('wikittyId', wikittyId) - .addClass("btn btn-success pull-right salesFunnelItemButton sent toAccepted") - .text("Accepté") - .click(sentToAccepted); - var aRejected = $('<a/>') - .attr('wikittyId', wikittyId) - .addClass("btn btn-danger pull-right salesFunnelItemButton sent toRejected") - .text("Rejeté") - .click(sentToRejected); + dialog.dialog( "close" ); - //rightDiv - var rightDiv = $("<div>").addClass("pull-right"); - var rightP = $("<p>").addClass("salesFunnelItemTitle").text(wikitty["Quotation.amount"] +" €"); - if (wikitty["Quotation.category"] != null) { - var smallInfo = $("<small>") - .text(data.preloaded[wikitty["Quotation.category"]].data["WikittyTreeNode.name"] - + ' - ' + wikitty["Quotation.estimatedDays"] + 'j - ' + - wikitty["Quotation.conversionHope"] + "%"); - } - rightDiv.append(rightP); - rightDiv.append(smallInfo); + }).fail(function(){ + //fail + //TODO JC20130212 retour utilisateur + dialog.dialog( "close" ); + }); + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + }, + open: function(event, ui) { + var date = new Date(); + $("#sendingDate").val(date.getDate() + "/" + (date.getMonth()+1)+"/"+date.getFullYear()); + } + }); - //clear:both - var clearBoth=$("<div style='clear:both;'/>") + //Passage d'un draft -> sent + $("a.draft").click(draftToSent); - li.append(leftDiv); - li.append(aAccepted); - li.append(aRejected); - li.append(rightDiv); - li.append(clearBoth); + $( "#dialog-form-draftToSent" ).dialog({ + autoOpen: false, + height: 300, + width: 350, + modal: true, + buttons: { + Ok: function() { - var sents = $(".sents"); - sents.append(li); - oldQuotation.slideUp(); + var sendingDate = $("#sendDate").val(); + var id = $("#draft-wikittyId").val(); + var oldQuotation = $(this).data('oldQuotation'); + var allFields = $([]).add($("#sendDate")).add($("#draft-wikittyId")) - //update draftAmount and draftAmountHope - var draftAmount = parseInt($("#draftAmount").text()) - wikitty["Quotation.amount"]; - var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; - var draftAmountHope = parseInt($("#draftAmountHope").text()) - amountHope; - $("#draftAmount").text(draftAmount); - $("#draftAmountHope").text(draftAmountHope); + var dialog = $( this ); - //update sentAmount and sentAmountHope - var sentAmount = parseInt($("#sentAmount").text()) + wikitty["Quotation.amount"]; - var sentAmountHope = parseInt($("#sentAmountHope").text()) + amountHope; - $("#sentAmount").text(sentAmount); - $("#sentAmountHope").text(sentAmountHope); + $.post(createUrl("/sales/funnel/json/send/", id,"?sendingDate=", sendingDate), + function(data){ + //success - }).fail(function(){ - //fail - //TODO JC20130212 retour utilisateur - }); - } + var wikittyId = data.meta.id; + var wikitty = data.data; - function sentToRejected(){ - var id = $(this).attr('wikittyId'); - var oldQuotation = $(this).parent(); - $.get(createUrl("/sales/funnel/json/reject/", id), - function(data){ - //success - oldQuotation.slideUp(); + var li = $("<li></li>").addClass("salesFunnelItem draft"); - var wikitty = data.data; + //leftDiv + var leftDiv = $("<div></div>").addClass("pull-left"); + var aIconEdit = $("<a></a>") + .attr("href",createUrl("/wikitty/edit/", wikittyId)); + var iconEdit = $("<i></i>").addClass("icon-edit"); + aIconEdit.append(iconEdit); + leftDiv.append(aIconEdit); + var smallAccount = $("<small></small>"); + if (wikitty["Quotation.customer"]!=null){ + var customer = data.preloaded[wikitty["Quotation.customer"]]; + var firstName = customer.preloaded[customer.data["Employee.person"]].data["Person.firstName"]; + var lastName = customer.preloaded[customer.data["Employee.person"]].data["Person.lastName"]; + var company = customer.preloaded[customer.data["Employee.company"]].data["Company.name"]; + } + var aAccount = $("<a></a>") + .text(firstName + " " + lastName + " (" + company + ")") + .attr("href", createUrl("/wikitty/Employee/view/", wikitty["Quotation.customer"])); + smallAccount.append(aAccount); + leftDiv.append(smallAccount); + var leftP = $("<p> - </p>"); + var itemTitleSpan = $('<span></span>').addClass('salesFunnelItemTitle'); - //update sentAmount and sentAmountHope - var sentAmount = parseInt($("#sentAmount").text()) - wikitty["Quotation.amount"]; - var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; - var sentAmountHope = parseInt($("#sentAmountHope").text()) - amountHope; - $("#sentAmount").text(sentAmount); - $("#sentAmountHope").text(sentAmountHope); - }).fail(function(){ - //fail - //TODO JC20130212 retour utilisateur - }); - } + if (wikitty["Quotation.project"]!=null) { + var aProject = $("<a/>") + .addClass("nameLink") + .attr("href" , createUrl("/wikitty/Project/view/", wikitty["Quotation.project"])) + .text(data.preloaded[wikitty["Quotation.project"]].data["Project.name"]); + } + itemTitleSpan.append(aProject); + var descriptionSmall = $('<small/>').text(wikitty["Quotation.description"]); + leftP.append(descriptionSmall); + leftP.prepend(itemTitleSpan); + leftDiv.append(leftP); - function sentToAccepted(){ - var id = $(this).attr('wikittyId'); - var oldQuotation = $(this).parent(); - $.get(createUrl("/sales/funnel/json/accept/", id), - function(data){ - //success - oldQuotation.slideUp(); + //button + var aAccepted = $('<a/>') + .attr('wikittyId', wikittyId) + .addClass("btn btn-success pull-right salesFunnelItemButton sent toAccepted") + .text("Accepté") + .click(sentToAccepted); + var aRejected = $('<a/>') + .attr('wikittyId', wikittyId) + .addClass("btn btn-danger pull-right salesFunnelItemButton sent toRejected") + .text("Rejeté") + .click(sentToRejected); + var aCancelled = $('<a/>') + .attr('wikittyId', wikittyId) + .addClass("btn btn-warning pull-right salesFunnelItemButton sent toCancelled") + .text("Annuler") + .click(toCancelled); - var wikitty = data.data; + //rightDiv + var rightDiv = $("<div>").addClass("pull-right"); + var rightP = $("<p>").addClass("salesFunnelItemTitle").text(wikitty["Quotation.amount"] +" €"); + if (wikitty["Quotation.category"] != null) { + var smallInfo = $("<small>") + .text(data.preloaded[wikitty["Quotation.category"]].data["WikittyTreeNode.name"] + + ' - ' + wikitty["Quotation.estimatedDays"] + 'j - ' + + wikitty["Quotation.conversionHope"] + "%"); + } + rightDiv.append(rightP); + rightDiv.append(smallInfo); - //update sentAmount and sentAmountHope - var sentAmount = parseInt($("#sentAmount").text()) - wikitty["Quotation.amount"]; - var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; - var sentAmountHope = parseInt($("#sentAmountHope").text()) - amountHope; - $("#sentAmount").text(sentAmount); - $("#sentAmountHope").text(sentAmountHope); - }).fail(function(){ - //fail - //TODO JC20130212 retour utilisateur - }); - } + //clear:both + var clearBoth=$("<div style='clear:both;'/>") - //Passage d'un lead -> draft - $("a.lead").click(leadToDraft); + li.append(leftDiv); + li.append(aAccepted); + li.append(aRejected); + li.append(aCancelled); + li.append(rightDiv); + li.append(clearBoth); - //Passage d'un draft -> sent - $("a.draft").click(draftToSent); + var sents = $(".sents"); + sents.append(li); + oldQuotation.slideUp(); - //Passage d'un sent vers accepted - $("a.toAccepted").click(sentToAccepted); + //update draftAmount and draftAmountHope + var draftAmount = parseInt($("#draftAmount").text()) - wikitty["Quotation.amount"]; + var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; + var draftAmountHope = parseInt($("#draftAmountHope").text()) - amountHope; + $("#draftAmount").text(draftAmount); + $("#draftAmountHope").text(draftAmountHope); - //Passage d'un sent vers rejected - $("a.toRejected").click(sentToRejected); + //update sentAmount and sentAmountHope + var sentAmount = parseInt($("#sentAmount").text()) + wikitty["Quotation.amount"]; + var sentAmountHope = parseInt($("#sentAmountHope").text()) + amountHope; + $("#sentAmount").text(sentAmount); + $("#sentAmountHope").text(sentAmountHope); + allFields.val(""); + dialog.dialog( "close" ); + + }).fail(function(){ + //fail + //TODO JC20130212 retour utilisateur + dialog.dialog( "close" ); + }); + + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + }, + open: function(event, ui) { + var date = new Date(); + $("#sendDate").val(date.getDate() + "/" + (date.getMonth()+1)+"/"+date.getFullYear()); + } + }); + + //Passage d'un sent vers accepted + $("a.toAccepted").click(sentToAccepted); + + $( "#dialog-form-sentToAccepted" ).dialog({ + autoOpen: false, + height: 300, + width: 350, + modal: true, + buttons: { + Ok: function() { + + var acceptedDate = $("#acceptedDate").val(); + var id = $("#sent-wikittyId").val(); + var oldQuotation = $(this).data('oldQuotation'); + var allFields = $([]).add($("#acceptedDate")).add($("#sent-wikittyId")) + + var dialog = $( this ); + + $.post(createUrl("/sales/funnel/json/accept/", id,"?acceptedDate=", acceptedDate), + function(data){ + //success + oldQuotation.slideUp(); + + var wikitty = data.data; + + //update sentAmount and sentAmountHope + var sentAmount = parseInt($("#sentAmount").text()) - wikitty["Quotation.amount"]; + var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; + var sentAmountHope = parseInt($("#sentAmountHope").text()) - amountHope; + $("#sentAmount").text(sentAmount); + $("#sentAmountHope").text(sentAmountHope); + + allFields.val(""); + + dialog.dialog( "close" ); + + }).fail(function(){ + //fail + //TODO JC20130212 retour utilisateur + dialog.dialog( "close" ); + }); + + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + }, + open: function(event, ui) { + var date = new Date(); + $("#acceptedDate").val(date.getDate() + "/" + (date.getMonth()+1)+"/"+date.getFullYear()); + } + }); + + //Passage d'un sent vers rejected + $("a.toRejected").click(sentToRejected); + + $( "#dialog-form-sentToRejected" ).dialog({ + autoOpen: false, + height: 300, + width: 350, + modal: true, + buttons: { + Ok: function() { + + var rejectedDate = $("#rejectedDate").val(); + var id = $("#rejected-wikittyId").val(); + var oldQuotation = $(this).data('oldQuotation'); + var allFields = $([]).add($("#rejectedDate")).add($("#rejected-wikittyId")) + + var dialog = $( this ); + + $.post(createUrl("/sales/funnel/json/reject/", id,"?rejectedDate=", rejectedDate), + function(data){ + //success + oldQuotation.slideUp(); + + var wikitty = data.data; + + //update sentAmount and sentAmountHope + var sentAmount = parseInt($("#sentAmount").text()) - wikitty["Quotation.amount"]; + var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; + var sentAmountHope = parseInt($("#sentAmountHope").text()) - amountHope; + $("#sentAmount").text(sentAmount); + $("#sentAmountHope").text(sentAmountHope); + + allFields.val(""); + + dialog.dialog( "close" ); + + }).fail(function(){ + //fail + //TODO JC20130212 retour utilisateur + dialog.dialog( "close" ); + }); + + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + }, + open: function(event, ui) { + var date = new Date(); + $("#rejectedDate").val(date.getDate() + "/" + (date.getMonth()+1)+"/"+date.getFullYear()); + } + }); + + //Passage vers cancelled + $("a.toCancelled").click(toCancelled); + + $( "#dialog-form-toCancelled" ).dialog({ + autoOpen: false, + height: 300, + width: 350, + modal: true, + buttons: { + Ok: function() { + + var cancelledDate = $("#cancelledDate").val(); + var reason = $("#cancelledReason").val(); + var id = $("#cancelled-wikittyId").val(); + var oldQuotation = $(this).data('oldQuotation'); + var allFields = $([]).add($("#cancelledDate")).add($("#cancelled-wikittyId")).add($("#cancelledReason")); + + var dialog = $( this ); + + $.post(createUrl("/sales/funnel/json/cancel/", id,"?cancelledDate=", cancelledDate,"&reason=",reason), + function(data){ + //success + oldQuotation.slideUp(); + + var wikitty = data.data; + + //TODO JC20130527 update amounts + //update sentAmount and sentAmountHope + //var sentAmount = parseInt($("#sentAmount").text()) - wikitty["Quotation.amount"]; + //var amountHope = wikitty["Quotation.amount"]*wikitty["Quotation.conversionHope"]/100; + //var sentAmountHope = parseInt($("#sentAmountHope").text()) - amountHope; + //$("#sentAmount").text(sentAmount); + //$("#sentAmountHope").text(sentAmountHope); + + allFields.val(""); + dialog.dialog( "close" ); + + }).fail(function(){ + //fail + //TODO JC20130212 retour utilisateur + dialog.dialog( "close" ); + }); + + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + close: function() { + }, + open: function(event, ui) { + var date = new Date(); + $("#cancelledDate").val(date.getDate() + "/" + (date.getMonth()+1)+"/"+date.getFullYear()); + } + }); + // ******************************************************************** // * PROJECT DASHBOARD * // ********************************************************************
participants (1)
-
jcouteau@users.chorem.org