This is an automated email from the git hooks/post-receive script. New commit to branch feature/882-angular in repository chorem. See http://git.chorem.org/chorem.git commit a258442dae7587b56c50d91aa9a7f2a2c57db361 Author: kootox <jean.couteau@gmail.com> Date: Wed Mar 11 16:17:35 2015 +0100 refs #882 : deal with invoices on companies --- .../webmotion/actions/crm/CategoryAction.java | 36 ++++ .../chorem/webmotion/actions/crm/CategoryDTO.java | 55 ++++++ .../webmotion/actions/crm/InvoiceAction.java | 126 +++++++++++++ .../chorem/webmotion/actions/crm/InvoiceDTO.java | 198 +++++++++++++++++++++ chorem-webmotion/src/main/resources/mapping | 8 + .../WEB-INF/jsp/crm/partials/companyPanel.html | 5 +- .../jsp/crm/partials/invoiceCreateCard.html | 99 +++++++++++ .../jsp/crm/partials/invoiceDetailCard.html | 58 ++++++ .../WEB-INF/jsp/crm/partials/invoiceEditCard.html | 106 +++++++++++ .../WEB-INF/jsp/crm/partials/invoicesListCard.html | 21 +++ chorem-webmotion/src/main/webapp/js/crm.js | 127 ++++++++++++- 11 files changed, 830 insertions(+), 9 deletions(-) diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryAction.java new file mode 100644 index 0000000..5e752b6 --- /dev/null +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryAction.java @@ -0,0 +1,36 @@ +package org.chorem.webmotion.actions.crm; + +import org.chorem.ChoremClient; +import org.chorem.entities.Category; +import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.render.Render; +import org.nuiton.wikitty.query.WikittyQuery; +import org.nuiton.wikitty.query.WikittyQueryMaker; +import org.nuiton.wikitty.query.WikittyQueryResult; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by couteau on 11/03/15. + */ +public class CategoryAction extends WebMotionController { + + public Render listCategories(ChoremClient client){ + WikittyQuery categoriesQuery = new WikittyQueryMaker().and() + .exteq(Category.EXT_CATEGORY) + .end().setLimit(WikittyQuery.MAX); + + WikittyQueryResult<String> categoriesId = client.findAllByQuery(categoriesQuery); + + List<Category> categories = client.restore(Category.class, categoriesId.getAll()); + + List<CategoryDTO> categoryDTOs = new ArrayList<>(); + + for (Category category:categories){ + categoryDTOs.add(new CategoryDTO(category)); + } + + return renderJSON(categoryDTOs); + } +} diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryDTO.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryDTO.java new file mode 100644 index 0000000..ee1202d --- /dev/null +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/CategoryDTO.java @@ -0,0 +1,55 @@ +package org.chorem.webmotion.actions.crm; + +import org.chorem.entities.Category; + +/** + * Created by couteau on 11/03/15. + */ +public class CategoryDTO { + + protected String wikittyId; + protected String name; + protected String parent; + protected int index; + + public String getWikittyId() { + return wikittyId; + } + + public void setWikittyId(String wikittyId) { + this.wikittyId = wikittyId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getParent() { + return parent; + } + + public void setParent(String parent) { + this.parent = parent; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public CategoryDTO(){} + + public CategoryDTO(Category category){ + this.wikittyId = category.getWikittyId(); + this.name = category.getName(); + this.parent = category.getParent(); + this.index = category.getIndex(); + } +} diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java new file mode 100644 index 0000000..b357f34 --- /dev/null +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java @@ -0,0 +1,126 @@ +package org.chorem.webmotion.actions.crm; + +import org.chorem.ChoremClient; +import org.chorem.entities.Invoice; +import org.chorem.entities.InvoiceImpl; +import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.render.Render; +import org.nuiton.wikitty.query.WikittyQuery; +import org.nuiton.wikitty.query.WikittyQueryMaker; +import org.nuiton.wikitty.query.WikittyQueryResult; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by couteau on 11/03/15. + */ +public class InvoiceAction extends WebMotionController { + + public Render listInvoicesForPayer(ChoremClient client, String payer){ + + WikittyQuery invoicesQuery = new WikittyQueryMaker().and() + .exteq(Invoice.EXT_INVOICE) + .eq(Invoice.FQ_FIELD_FINANCIALTRANSACTION_PAYER, payer) + .end().setLimit(WikittyQuery.MAX); + + WikittyQueryResult<String> invoicesId = client.findAllByQuery(invoicesQuery); + + List<Invoice> invoices = client.restore(Invoice.class, invoicesId.getAll(), + "FinancialTransaction.payer", + "FinancialTransaction.beneficiary", + "FinancialTransaction.category"); + + List<InvoiceDTO> invoiceDTOs = new ArrayList<>(); + + for (Invoice invoice:invoices){ + invoiceDTOs.add(new InvoiceDTO(invoice, client)); + } + + return renderJSON(invoiceDTOs); + } + + public Render getInvoice(ChoremClient client, String id) { + Invoice invoice = client.restore(Invoice.class, id, + "FinancialTransaction.payer", + "FinancialTransaction.beneficiary", + "FinancialTransaction.category"); + + InvoiceDTO dto = new InvoiceDTO(invoice, client); + + return renderJSON(dto); + + } + + public Render createInvoice(ChoremClient client, InvoiceDTO dto){ + + Invoice invoice = new InvoiceImpl(); + + invoice.setStatus(dto.getStatus()); + invoice.setAmount(dto.getAmount()); + invoice.setDescription(dto.getDescription()); + invoice.setPaymentDate(dto.getPaymentDate()); + invoice.setEmittedDate(dto.getEmittedDate()); + invoice.setExpectedDate(dto.getExpectedDate()); + invoice.setReference(dto.getReference()); + invoice.setVAT(dto.getVat()); + + if(dto.getCategory() != null) { + invoice.setCategory(dto.getCategory().getWikittyId()); + } else { + invoice.setCategory(dto.getCategoryId()); + } + + if(dto.getPayer() != null) { + invoice.setPayer(dto.getPayer().getWikittyId()); + } else { + invoice.setPayer(dto.getPayerId()); + } + + invoice = client.store(invoice); + + dto = new InvoiceDTO(invoice, client); + + return renderJSON(dto); + + } + + public Render updateInvoice(ChoremClient client, String id, InvoiceDTO dto){ + + Invoice invoice = client.restore(Invoice.class, id); + + invoice.setStatus(dto.getStatus()); + invoice.setAmount(dto.getAmount()); + invoice.setDescription(dto.getDescription()); + invoice.setPaymentDate(dto.getPaymentDate()); + invoice.setEmittedDate(dto.getEmittedDate()); + invoice.setExpectedDate(dto.getExpectedDate()); + invoice.setReference(dto.getReference()); + invoice.setVAT(dto.getVat()); + + if(dto.getCategory() != null) { + invoice.setCategory(dto.getCategory().getWikittyId()); + } else { + invoice.setCategory(dto.getCategoryId()); + } + + if(dto.getPayer() != null) { + invoice.setPayer(dto.getPayer().getWikittyId()); + } else { + invoice.setPayer(dto.getPayerId()); + } + + invoice = client.store(invoice); + + dto = new InvoiceDTO(invoice, client); + + return renderJSON(dto); + + } + + public Render deleteInvoice(ChoremClient client, String id) { + client.delete(id); + + return renderSuccess(); + } +} diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceDTO.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceDTO.java new file mode 100644 index 0000000..1a1262a --- /dev/null +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceDTO.java @@ -0,0 +1,198 @@ +package org.chorem.webmotion.actions.crm; + +import org.chorem.ChoremClient; +import org.chorem.entities.Category; +import org.chorem.entities.Company; +import org.chorem.entities.CompanyImpl; +import org.chorem.entities.Invoice; + +import java.util.Date; + +/** + * Created by couteau on 10/03/15. + */ +public class InvoiceDTO { + + protected String reference; + protected String description; + protected double amount; + protected double vat; + protected Date emittedDate; + protected Date expectedDate; + protected Date paymentDate; + protected String payerId; + protected CompanyDTO payer; + protected String beneficiaryId; + protected CompanyDTO beneficiary; + protected String target; + protected String categoryId; + protected CategoryDTO category; + protected String status; + protected String wikittyId; + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + public double getVat() { + return vat; + } + + public void setVat(double vat) { + this.vat = vat; + } + + public Date getEmittedDate() { + return emittedDate; + } + + public void setEmittedDate(Date emittedDate) { + this.emittedDate = emittedDate; + } + + public Date getExpectedDate() { + return expectedDate; + } + + public void setExpectedDate(Date expectedDate) { + this.expectedDate = expectedDate; + } + + public Date getPaymentDate() { + return paymentDate; + } + + public void setPaymentDate(Date paymentDate) { + this.paymentDate = paymentDate; + } + + public String getPayerId() { + return payerId; + } + + public void setPayerId(String payerId) { + this.payerId = payerId; + } + + public CompanyDTO getPayer() { + return payer; + } + + public void setPayer(CompanyDTO payer) { + this.payer = payer; + } + + public String getBeneficiaryId() { + return beneficiaryId; + } + + public void setBeneficiaryId(String beneficiaryId) { + this.beneficiaryId = beneficiaryId; + } + + public CompanyDTO getBeneficiary() { + return beneficiary; + } + + public void setBeneficiary(CompanyDTO beneficiary) { + this.beneficiary = beneficiary; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getCategoryId() { + return categoryId; + } + + public void setCategoryId(String categoryId) { + this.categoryId = categoryId; + } + + public CategoryDTO getCategory() { + return category; + } + + public void setCategory(CategoryDTO category) { + this.category = category; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getWikittyId() { + return wikittyId; + } + + public void setWikittyId(String wikittyId) { + this.wikittyId = wikittyId; + } + + public InvoiceDTO(){} + + public InvoiceDTO(Invoice invoice, ChoremClient client){ + + this.reference = invoice.getReference(); + this.description = invoice.getDescription(); + this.amount = invoice.getAmount(); + this.vat = invoice.getVAT(); + this.emittedDate = invoice.getEmittedDate(); + this.expectedDate = invoice.getExpectedDate(); + this.paymentDate = invoice.getPaymentDate(); + this.payerId = invoice.getPayer(); + this.beneficiaryId = invoice.getBeneficiary(); + + Company company = client.restore(Company.class, invoice.getBeneficiary(), true); + + if (company != null) { + this.beneficiary = new CompanyDTO(company); + } + + company = client.restore(Company.class, invoice.getPayer(), true); + if (company != null) { + this.payer = new CompanyDTO(company); + } + + this.target = invoice.getTarget(); + this.categoryId = invoice.getCategory(); + + Category category = invoice.getCategory(false); + if (category != null) { + this.category = new CategoryDTO(category); + } + + this.status = invoice.getStatus(); + this.wikittyId = invoice.getWikittyId(); + + } +} diff --git a/chorem-webmotion/src/main/resources/mapping b/chorem-webmotion/src/main/resources/mapping index 3746a97..5e31957 100644 --- a/chorem-webmotion/src/main/resources/mapping +++ b/chorem-webmotion/src/main/resources/mapping @@ -121,6 +121,14 @@ GET /crm/employees/{id} action:crm.EmployeeAction.getEmployee POST /crm/employees/{id} action:crm.EmployeeAction.updateEmployee DELETE /crm/employees/{id} action:crm.EmployeeAction.deleteEmployee +GET /crm/invoices?payer={id} action:crm.InvoiceAction.listInvoicesForPayer +GET /crm/invoices/{id} action:crm.InvoiceAction.getInvoice +PUT /crm/invoices/add action:crm.InvoiceAction.createInvoice +POST /crm/invoices/{id} action:crm.InvoiceAction.updateInvoice +DELETE /crm/invoices/{id} action:crm.InvoiceAction.deleteInvoice + +GET /crm/categories action:crm.CategoryAction.listCategories + GET /crm/persons action:crm.PersonAction.listPersons GET /crm/partials/{page} view:crm/partials/{page} diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/companyPanel.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/companyPanel.html index bcf7732..c539ac1 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/companyPanel.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/companyPanel.html @@ -8,4 +8,7 @@ <ng-include src="'partials/notesListCard.html'"></ng-include> <!--employees card --> -<ng-include src="'partials/employeesListCard.html'"></ng-include> \ No newline at end of file +<ng-include src="'partials/employeesListCard.html'"></ng-include> + +<!--invoices card--> +<ng-include src="'partials/invoicesListCard.html'"></ng-include> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html new file mode 100644 index 0000000..2475e54 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html @@ -0,0 +1,99 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Créer une facture</h3> + <div class="btn-group pull-right"> + <button class="btn btn-danger" ng-click="cancel()"> + <i class="fa fa-times"></i> + Annuler + </button> + <button class="btn btn-success" ng-click="save()"> + <i class="fa fa-check"></i> + Sauver + </button> + </div> + </div> + + <div class="modal-body"> + <form class="form-horizontal"> + + <div class="form-group"> + <label class="col-xs-3 control-label">Référence</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.reference"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Montant</label> + <div class="col-xs-9"> + <div class="input-group"> + <input type="number" class="form-control" ng-model="invoice.amount"> + <span class="input-group-addon">€</span> + </div> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">TVA</label> + <div class="col-xs-9"> + <div class="input-group"> + <input type="number" class="form-control" ng-model="invoice.vat"> + <span class="input-group-addon">%</span> + </div> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Description</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.description"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Émission</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.emittedDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Échéance</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.expectedDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Paiement</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.paymentDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Catégorie</label> + <div class="col-xs-9"> + <ui-select ng-model="invoice.category" theme="select2" class="col-xs-9"> + <ui-select-match placeholder="Entrez le nom de la catégorie">{{$select.selected.name}}</ui-select-match> + <ui-select-choices repeat="category in categories | propsFilter: {name: $select.search}"> + <span ng-bind-html="''+category.name | highlight: $select.search"></span> + </ui-select-choices> + </ui-select> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Statut</label> + <div class="col-xs-9"> + <select ng-model="invoice.status" class="form-control"> + <option selected>ACCEPTED</option> + <option>CANCELLED</option> + </select> + </div> + </div> + + </form> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html new file mode 100644 index 0000000..68a4708 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html @@ -0,0 +1,58 @@ +<div class="panel panel-default"> + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Détails de la facture</h3> + <div class="btn-group pull-right visible-xs"> + <a class="btn btn-primary" href="#/companies/{{company.wikittyId}}/invoices/{{invoice.wikittyId}}/edit"> + <i class="fa fa-pencil"></i> + <span>Edit</span> + </a> + </div> + <a class="btn btn-primary pull-right hidden-xs" + href="#/companies/{{company.wikittyId}}/invoices/{{invoice.wikittyId}}/edit"> + <i class="fa fa-pencil"></i> + <span>Edit</span> + </a> + </div> + <div class="list-group"> + <div class="list-group-item"> + <label>Référence</label> + <h4 class="list-group-item-heading">{{invoice.reference}}</h4> + </div> + <div class="list-group-item"> + <label>Montant</label> + <h4 class="list-group-item-heading">{{invoice.amount|currency}}</h4> + </div> + <div class="list-group-item"> + <label>TVA</label> + <h4 class="list-group-item-heading">{{invoice.vat}} %</h4> + </div> + <div class="list-group-item"> + <label>Description</label> + <h4 class="list-group-item-heading">{{invoice.description}}</h4> + </div> + <div class="list-group-item"> + <label>Émission</label> + <h4 class="list-group-item-heading">{{invoice.emittedDate}}</h4> + </div> + <div class="list-group-item"> + <label>Limite de paiement</label> + <h4 class="list-group-item-heading">{{invoice.expectedDate}}</h4> + </div> + <div class="list-group-item"> + <label>Paiement</label> + <h4 class="list-group-item-heading">{{invoice.paymentDate}}</h4> + </div> + <div class="list-group-item"> + <label>Target</label> + <h4 class="list-group-item-heading">{{invoice.target}}</h4> + </div> + <div class="list-group-item"> + <label>Catégorie</label> + <h4 class="list-group-item-heading">{{invoice.category.name}}</h4> + </div> + <div class="list-group-item"> + <label>Statut</label> + <h4 class="list-group-item-heading">{{invoice.status}}</h4> + </div> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html new file mode 100644 index 0000000..812ee17 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html @@ -0,0 +1,106 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Éditer une facture</h3> + <div class="btn-group pull-right"> + <button class="btn btn-danger" ng-click="cancel()"> + <i class="fa fa-times"></i> + Annuler + </button> + <button class="btn btn-success" ng-click="save()"> + <i class="fa fa-check"></i> + Sauver + </button> + </div> + </div> + + <div class="modal-body"> + <form class="form-horizontal"> + + <div class="form-group"> + <label class="col-xs-3 control-label">Référence</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.reference"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Montant</label> + <div class="col-xs-9"> + <div class="input-group"> + <input type="number" class="form-control" ng-model="invoice.amount"> + <span class="input-group-addon">€</span> + </div> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">TVA</label> + <div class="col-xs-9"> + <div class="input-group"> + <input type="number" class="form-control" ng-model="invoice.vat"> + <span class="input-group-addon">%</span> + </div> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Description</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.description"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Émission</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.emittedDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Échéance</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.expectedDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Paiement</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="invoice.paymentDate"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Catégorie</label> + <div class="col-xs-9"> + <ui-select ng-model="invoice.category" theme="select2" class="col-xs-9"> + <ui-select-match placeholder="Entrez le nom de la catégorie">{{$select.selected.name}}</ui-select-match> + <ui-select-choices repeat="category in categories | propsFilter: {name: $select.search}"> + <span ng-bind-html="''+category.name | highlight: $select.search"></span> + </ui-select-choices> + </ui-select> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Statut</label> + <div class="col-xs-9"> + <select ng-model="invoice.status" class="form-control"> + <option>ACCEPTED</option> + <option>CANCELLED</option> + </select> + </div> + </div> + + </form> + </div> + + <div class="panel-footer"> + <button class="btn btn-danger btn-block" ng-click="delete()"> + <i class="fa fa-trash-o"></i> + Supprimer la facture + </button> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoicesListCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoicesListCard.html new file mode 100644 index 0000000..89d5ad6 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoicesListCard.html @@ -0,0 +1,21 @@ +<div class="panel panel-default"> + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Factures</h3> + <div class="btn-group pull-right visible-xs"> + <a class="btn btn-primary" href="#/companies/{{company.wikittyId}}/invoices/add"> + <i class="fa fa-pencil"></i> + <span>Ajouter</span> + </a> + </div> + <a class="btn btn-primary pull-right hidden-xs" href="#/companies/{{company.wikittyId}}/invoices/add"> + <i class="fa fa-plus"></i> + <span>Ajouter</span> + </a> + </div> + <div class="list-group"> + <a class="list-group-item" ng-repeat="invoice in invoices" href="#/companies/{{company.wikittyId}}/invoices/{{invoice.wikittyId}}"/> + <label>{{invoice.emittedDate | date : dd/MM/yyy}} - {{invoice.description}}</label> + <h4 class="list-group-item-heading">{{invoice.reference}} - {{invoice.amount|currency}}</h4> + </a> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/js/crm.js b/chorem-webmotion/src/main/webapp/js/crm.js index 0859bc2..1298558 100644 --- a/chorem-webmotion/src/main/webapp/js/crm.js +++ b/chorem-webmotion/src/main/webapp/js/crm.js @@ -54,7 +54,19 @@ crmTest.config(['$routeProvider', when('/companies/:companyId/employees/:employeeId/edit', { templateUrl:'partials/employeeEditCard.html', - controller:'EmployeeEditController'}); + controller:'EmployeeEditController'}). + + when('/companies/:companyId/invoices/add', { + templateUrl:'partials/invoiceCreateCard.html', + controller:'InvoiceCreateController'}). + + when('/companies/:companyId/invoices/:invoiceId', { + templateUrl:'partials/invoiceDetailCard.html', + controller:'InvoiceDetailController'}). + + when('/companies/:companyId/invoices/:invoiceId/edit', { + templateUrl:'partials/invoiceEditCard.html', + controller:'InvoiceEditController'}); }]); /**For select 2 filtering -> OR between search terms instead of AND**/ @@ -206,17 +218,27 @@ crmTest.controller('CompanyDetailController', function ($scope, $http, $routePar }; //get back employees for the company - $scope.updateEmployees=function(){ - if ($scope.company){ - $http.get('employees?company='+$scope.company.wikittyId).success(function(data){ - $scope.employees = data; - }); - } - }; + $scope.updateEmployees=function(){ + if ($scope.company){ + $http.get('employees?company='+$scope.company.wikittyId).success(function(data){ + $scope.employees = data; + }); + } + }; + + //get back invoices for the company + $scope.updateInvoices=function(){ + if ($scope.company){ + $http.get('invoices?payer='+$scope.company.wikittyId).success(function(data){ + $scope.invoices = data; + }); + } + }; $scope.updateContactDetails(); $scope.updateNotes(); $scope.updateEmployees(); + $scope.updateInvoices(); }); @@ -560,4 +582,93 @@ crmTest.controller('EmployeeCreateController', function ($scope, $http, $window) $scope.cancel = function(){ $window.history.back(); } +}); + +crmTest.controller('InvoiceDetailController', function ($scope, $http, $routeParams){ + + $scope.company=$scope.selectedItem; + + $http.get('invoices/'+$routeParams.invoiceId).success(function(data){ + $scope.invoice = data; + }); + +}); + +crmTest.controller('InvoiceCreateController', function ($scope, $http, $window) { + + $scope.company = $scope.selectedItem; + + $scope.invoice={}; + + //default status + $scope.invoice.status="ACCEPTED"; + + //get all categories + $http.get('categories').success(function(data){ + $scope.categories = data; + }); + + $scope.save = function(){ + + $scope.invoice.payer = $scope.company; + + $http({ + method : 'PUT', + url : 'invoices/add', + data : $.param($scope.invoice), // pass in data as strings + headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) + }) + .success(function(data) { + $window.history.back(); + }); + }; + + $scope.cancel = function(){ + $window.history.back(); + } +}); + +crmTest.controller('InvoiceEditController', function ($scope, $http, $window, $routeParams) { + + $scope.company = $scope.selectedItem; + + $scope.invoice={}; + + $http.get('invoices/'+$routeParams.invoiceId).success(function(data){ + $scope.invoice = data; + }); + + //get all categories + $http.get('categories').success(function(data){ + $scope.categories = data; + }); + + $scope.save = function(){ + + $scope.invoice.payer = $scope.company; + + $http({ + method : 'POST', + url : 'invoices/'+$scope.invoice.wikittyId, + data : $.param($scope.invoice), // pass in data as strings + headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) + }) + .success(function(data) { + $window.history.back(); + }); + }; + + $scope.cancel = function(){ + $window.history.back(); + } + + $scope.delete = function(){ + if(confirm('Are you sure you want to delete?')){ + $http.delete('invoices/'+$scope.invoice.wikittyId).success(function(data){ + + $window.history.back(); + $window.history.back(); + }); + } + } }); \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.