Esempio n. 1
0
        public IActionResult PutInvoice([FromRoute] int deliveryOrderId, [FromBody] InvoiceFormDto form)
        {
            try
            {
                VerifyUser();

                var id = _service.UpdateFromInvoice(deliveryOrderId, form);

                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(NoContent());
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
Esempio n. 2
0
        public async Task <int> Create(GarmentInvoice model, string username, int clientTimeZoneOffset = 7)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    double _total = 0;
                    EntityExtension.FlagForCreate(model, username, USER_AGENT);
                    if (model.UseIncomeTax)
                    {
                        model.NPH = GenerateNPH();
                    }
                    if (model.UseVat)
                    {
                        model.NPN = GenerateNPN();
                    }
                    foreach (var item in model.Items)
                    {
                        _total += item.TotalAmount;
                        GarmentDeliveryOrder deliveryOrder = dbSetDeliveryOrder.FirstOrDefault(s => s.Id == item.DeliveryOrderId);
                        if (deliveryOrder != null)
                        {
                            deliveryOrder.IsInvoice = true;
                        }
                        EntityExtension.FlagForCreate(item, username, USER_AGENT);

                        foreach (var detail in item.Details)
                        {
                            EntityExtension.FlagForCreate(detail, username, USER_AGENT);
                        }
                    }
                    model.TotalAmount = _total;

                    this.dbSet.Add(model);
                    Created = await dbContext.SaveChangesAsync();

                    foreach (var item in model.Items)
                    {
                        var deliveryOrder = dbSetDeliveryOrder.FirstOrDefault(s => s.Id == item.DeliveryOrderId);
                        if (deliveryOrder != null)
                        {
                            var amount                  = 0.0;
                            var currencyAmount          = 0.0;
                            var vatAmount               = 0.0;
                            var currencyVATAmount       = 0.0;
                            var incomeTaxAmount         = 0.0;
                            var currencyIncomeTaxAmount = 0.0;

                            if (model.CurrencyCode == "IDR")
                            {
                                amount = item.TotalAmount;
                                if (model.IsPayVat)
                                {
                                    vatAmount = item.TotalAmount * 0.1;
                                    //vatAmount = item.TotalAmount * (model.VatRate / 100);
                                }

                                if (model.IsPayTax)
                                {
                                    incomeTaxAmount = item.TotalAmount * model.IncomeTaxRate / 100;
                                }
                            }
                            else
                            {
                                amount         = item.TotalAmount * deliveryOrder.DOCurrencyRate.GetValueOrDefault();
                                currencyAmount = item.TotalAmount;
                                if (model.IsPayVat)
                                {
                                    vatAmount = amount * 0.1;
                                    //vatAmount = amount * (model.VatRate / 100);
                                    currencyVATAmount = item.TotalAmount * 0.1;
                                    //currencyVATAmount = item.TotalAmount * (model.VatRate / 100);
                                }

                                if (model.IsPayTax)
                                {
                                    incomeTaxAmount         = amount * model.IncomeTaxRate / 100;
                                    currencyIncomeTaxAmount = item.TotalAmount * model.IncomeTaxRate / 100;
                                }
                            }

                            await _garmentDebtBalanceService.UpdateFromInvoice((int)deliveryOrder.Id, new InvoiceFormDto((int)model.Id, model.InvoiceDate, model.InvoiceNo, amount, currencyAmount, vatAmount, incomeTaxAmount, model.IsPayVat, model.IsPayTax, currencyVATAmount, currencyIncomeTaxAmount, model.VatNo));
                        }
                    }

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }