public SalesInvoice ConfirmObject(SalesInvoice salesInvoice, DateTime ConfirmationDate, ISalesInvoiceDetailService _salesInvoiceDetailService, ISalesOrderService _salesOrderService, IDeliveryOrderService _deliveryOrderService, IDeliveryOrderDetailService _deliveryOrderDetailService, IReceivableService _receivableService) { salesInvoice.ConfirmationDate = ConfirmationDate; if (_validator.ValidConfirmObject(salesInvoice, _salesInvoiceDetailService, _deliveryOrderService, _deliveryOrderDetailService)) { // confirm details // add all amount into amountreceivable IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); foreach (var detail in details) { detail.Errors = new Dictionary <string, string>(); _salesInvoiceDetailService.ConfirmObject(detail, ConfirmationDate, _deliveryOrderDetailService); } salesInvoice = CalculateAmountReceivable(salesInvoice, _salesInvoiceDetailService); // confirm object // create receivable salesInvoice = _repository.ConfirmObject(salesInvoice); DeliveryOrder deliveryOrder = _deliveryOrderService.GetObjectById(salesInvoice.DeliveryOrderId); _deliveryOrderService.CheckAndSetInvoiceComplete(deliveryOrder, _deliveryOrderDetailService); SalesOrder salesOrder = _salesOrderService.GetObjectById(deliveryOrder.SalesOrderId); Receivable receivable = _receivableService.CreateObject(salesOrder.ContactId, Constant.ReceivableSource.SalesInvoice, salesInvoice.Id, salesInvoice.AmountReceivable, salesInvoice.DueDate); } return(salesInvoice); }
public SalesInvoice VHasSalesInvoiceDetails(SalesInvoice salesInvoice, ISalesInvoiceDetailService _salesInvoiceDetailService) { IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); if (!details.Any()) { salesInvoice.Errors.Add("Generic", "Tidak memiliki Sales Invoice Details"); } return(salesInvoice); }
public SalesInvoiceDetail VIsUniqueDeliveryOrderDetail(SalesInvoiceDetail salesInvoiceDetail, ISalesInvoiceDetailService _salesInvoiceDetail, IDeliveryOrderDetailService _deliveryOrderDetailService) { IList <SalesInvoiceDetail> details = _salesInvoiceDetail.GetObjectsBySalesInvoiceId(salesInvoiceDetail.SalesInvoiceId); foreach (var detail in details) { if (detail.DeliveryOrderDetailId == salesInvoiceDetail.DeliveryOrderDetailId && detail.Id != salesInvoiceDetail.Id) { salesInvoiceDetail.Errors.Add("Generic", "Tidak boleh memiliki lebih dari 2 Sales Receival Detail"); } } return(salesInvoiceDetail); }
public SalesInvoice CalculateAmountReceivable(SalesInvoice salesInvoice, ISalesInvoiceDetailService _salesInvoiceDetailService) { IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); decimal AmountReceivable = 0; foreach (var detail in details) { AmountReceivable += detail.Amount; } decimal Discount = salesInvoice.Discount / 100 * AmountReceivable; decimal TaxableAmount = AmountReceivable - Discount; salesInvoice.AmountReceivable = TaxableAmount * (decimal)1.1; // 10% Tax _repository.Update(salesInvoice); return(salesInvoice); }
public SalesInvoice VAllSalesInvoiceDetailsAreConfirmable(SalesInvoice salesInvoice, ISalesInvoiceDetailService _salesInvoiceDetailService, IDeliveryOrderDetailService _deliveryOrderDetailService) { IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); foreach (var detail in details) { detail.ConfirmationDate = salesInvoice.ConfirmationDate; _salesInvoiceDetailService.GetValidator().VConfirmObject(detail, _salesInvoiceDetailService, _deliveryOrderDetailService); foreach (var error in detail.Errors) { salesInvoice.Errors.Add(error.Key, error.Value); } if (!isValid(salesInvoice)) { return(salesInvoice); } } return(salesInvoice); }
public SalesInvoice VAllSalesInvoiceDetailsAreUnconfirmable(SalesInvoice salesInvoice, ISalesInvoiceDetailService _salesInvoiceDetailService, IReceiptVoucherDetailService _receiptVoucherDetailService, IReceivableService _receivableService) { IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); foreach (var detail in details) { if (!_salesInvoiceDetailService.GetValidator().ValidUnconfirmObject(detail)) { foreach (var error in detail.Errors) { salesInvoice.Errors.Add(error.Key, error.Value); } if (!isValid(salesInvoice)) { return(salesInvoice); } } } return(salesInvoice); }
public SalesInvoice UnconfirmObject(SalesInvoice salesInvoice, ISalesInvoiceDetailService _salesInvoiceDetailService, IDeliveryOrderService _deliveryOrderService, IDeliveryOrderDetailService _deliveryOrderDetailService, IReceiptVoucherDetailService _receiptVoucherDetailService, IReceivableService _receivableService) { if (_validator.ValidUnconfirmObject(salesInvoice, _salesInvoiceDetailService, _receiptVoucherDetailService, _receivableService)) { IList <SalesInvoiceDetail> details = _salesInvoiceDetailService.GetObjectsBySalesInvoiceId(salesInvoice.Id); foreach (var detail in details) { detail.Errors = new Dictionary <string, string>(); _salesInvoiceDetailService.UnconfirmObject(detail, _deliveryOrderService, _deliveryOrderDetailService); } _repository.UnconfirmObject(salesInvoice); DeliveryOrder deliveryOrder = _deliveryOrderService.GetObjectById(salesInvoice.DeliveryOrderId); _deliveryOrderService.UnsetInvoiceComplete(deliveryOrder); Receivable receivable = _receivableService.GetObjectBySource(Constant.ReceivableSource.SalesInvoice, salesInvoice.Id); _receivableService.SoftDeleteObject(receivable); } return(salesInvoice); }