public static void Delete(int p_id_ProductSell) { var ps = Get(p_id_ProductSell); var invoice = InvoiceSell.Get((int)ps.ID_INVOICES_SELLS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } _db.PRODUCTS_SELLS.Remove(ps); _db.SaveChanges(); }
public static void Add(PRODUCTS_SELLS p_ProductSell, double p_Quantity = 1) { var invoice = InvoiceSell.Get((int)p_ProductSell.ID_INVOICES_SELLS); var p = product.Get((int)p_ProductSell.ID_PRODUCTS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } if ((p.QUANTITY - p_Quantity) < 0) { DialogError.Error(); return; } _db.PRODUCTS_SELLS.Add(p_ProductSell); _db.SaveChanges(); }
public static void EditStampOfProductSell(double p_Stamp, int id_ProductSell) { if (p_Stamp < 0) { DialogError.Error(); return; } var ps = Get(id_ProductSell); var invoice = InvoiceSell.Get((int)ps.ID_INVOICES_SELLS); //var p = product.Get((int)ps.ID_PRODUCTS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } ps.STAMP = p_Stamp; _db.SaveChanges(); }
public async Task <IActionResult> InvoiceSellGen(int id, bool invoiceInPLN) { var dbRes = await this.TransportOfferQueryable() .FirstOrDefaultAsync(f => f.TransportOfferId == id); if (dbRes == null) { //return BadRequest(bp.sharedLocal.ModelStateHelpful.ModelStateHelpful.ModelError("Error", $"Nie znaleziono transportu o Id: {id}")); return(NotFound()); } if (dbRes.InvoiceSell != null) { return(BadRequest(bp.sharedLocal.ModelStateHelpful.ModelStateHelpful.ModelError("Error", $"Transportu o Id: {id}, ma już utworzoną FV {dbRes.InvoiceSell.InvoiceNo}"))); } var dbInv = new InvoiceSell(); var transportDTO = this.EtDTOTransportOffer(dbRes); transportDTO.InvoiceInPLN = invoiceInPLN; await this.UpdateInvoiceSell(dbInv, transportDTO); dbInv.TransportOffer = dbRes; this._db.Entry(dbInv).State = EntityState.Added; try { await this._db.SaveChangesAsync(); } catch (Exception e) { throw e; } return(NoContent()); }
public static void AddProductSell(int p_id_product, int p_id_invoice, double p_quantity = 1) { var invoice = InvoiceSell.Get(p_id_invoice); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } if (IsExistProductInInvoice(p_id_product, p_id_invoice)) { DialogError.Error(); return; } if (p_quantity < 0) { DialogError.Error(); return; } var p = product.Get(p_id_product); double p_MONEY = p.MONEY_SELLING_1; double p_QUANTITY = p_quantity; double p_TAX_PERCE = p.TAX_PERCE; double p_STAMP = 0; double p_TAX_VALUE = p.TAX_PERCE / 100 * p.MONEY_SELLING_1; double MONEY_PAID = (p_MONEY + p_TAX_VALUE + p_STAMP) * p_QUANTITY; PRODUCTS_SELLS ps = new PRODUCTS_SELLS { ID = NewId(), ID_PRODUCTS = p_id_product, ID_INVOICES_SELLS = p_id_invoice, QUANTITY = p_QUANTITY, MONEY_UNIT = p_MONEY, TAX_PERCE = p_TAX_PERCE, STAMP = 0 }; Add(ps); }
public static void EditQuantityOfProductSell(double p_Quantity, int id_ProductSell) { if (p_Quantity < 0) { DialogError.Error(); return; } var ps = Get(id_ProductSell); var invoice = InvoiceSell.Get((int)ps.ID_INVOICES_SELLS); var p = product.Get((int)ps.ID_PRODUCTS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } if ((p.QUANTITY - p_Quantity) < 0) { DialogError.Error(); return; } ps.QUANTITY = p_Quantity; _db.SaveChanges(); }
public static void EditMoneyUnitOfProductSell(double p_MoneyUnit, int id_ProductSell) { if (p_MoneyUnit < 0) { DialogError.Error(); return; } var ps = Get(id_ProductSell); var invoice = InvoiceSell.Get((int)ps.ID_INVOICES_SELLS); var p = product.Get((int)ps.ID_PRODUCTS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } if (p_MoneyUnit < p.MONEY_SELLING_MIN) { DialogError.Error(); return; } ps.MONEY_UNIT = p_MoneyUnit; _db.SaveChanges(); }
public static void EditTaxPerceOfProductSell(double p_TaxPerce, int id_ProductSell) { if (p_TaxPerce < 0) { DialogError.Error(); return; } if (p_TaxPerce > 100) { DialogError.Error(); return; } var ps = Get(id_ProductSell); var invoice = InvoiceSell.Get((int)ps.ID_INVOICES_SELLS); //var p = product.Get((int)ps.ID_PRODUCTS); if (invoice.VALIDATION == 1) { DialogError.Error(); return; } ps.TAX_PERCE = p_TaxPerce; _db.SaveChanges(); }
public async Task <IActionResult> Put(int id, [FromBody] InvoiceSellDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dbInvoice = new InvoiceSell(); if (id > 0) { dbInvoice = await this._invoiceService.QueryableInvoiceSell() .FirstOrDefaultAsync(f => f.InvoiceSellId == id); if (dbInvoice == null) { return(BadRequest(bp.sharedLocal.ModelStateHelpful.ModelStateHelpful.ModelError("Error", $"Nie znaleziono faktury o Id: {id}"))); } } else { this._db.Entry(dbInvoice).State = EntityState.Added; } //correction - create NEW if (dto.IsCorrection && dto.InvoiceNo == null) { //setting inActive var newInvCorr = new InvoiceSell(); this._invoiceService.InvoiceSellCorrectionSetInactive(dbInvoice); newInvCorr.BaseInvoiceId = dbInvoice.InvoiceSellId; await this._invoiceService.MapperInvoiceSell(newInvCorr, dto, User); this._db.Entry(newInvCorr).State = EntityState.Added; try { await this._db.SaveChangesAsync(); //setting new correctionID dbInvoice.CorrectiondId = newInvCorr.InvoiceSellId; await this._db.SaveChangesAsync(); } catch (Exception e) { throw e; } var correctedDTO = this._invoiceService.EtoDTOInvoiceSellForInvoiceCorrection(this._invoiceService.EtoDTOInvoiceSell(newInvCorr), this._invoiceService.EtoDTOInvoiceSell(dbInvoice)); return(Ok(correctedDTO)); } if (dto.IsCorrection && dto.InvoiceNo != null) { if (dbInvoice.IsInactive == false) { await this._invoiceService.MapperInvoiceSell(dbInvoice, dto, User); await this._db.SaveChangesAsync(); } var baseInvoice = await this._invoiceService.QueryableInvoiceSell() .FirstOrDefaultAsync(f => f.InvoiceSellId == dbInvoice.BaseInvoiceId.Value); return(Ok(this._invoiceService.EtoDTOInvoiceSellForInvoiceCorrection(this._invoiceService.EtoDTOInvoiceSell(dbInvoice), this._invoiceService.EtoDTOInvoiceSell(baseInvoice)))); } if (dbInvoice.IsInactive == false) { await this._invoiceService.MapperInvoiceSell(dbInvoice, dto, User); } try { await this._db.SaveChangesAsync(); } catch (Exception e) { throw e; } return(Ok(this._invoiceService.EtoDTOInvoiceSell(dbInvoice))); }
private async Task UpdateInvoiceSell(InvoiceSell dbInv, TransportOfferDTO dto) { var tradeInfoDTO = dto.TradeInfo; if (dbInv.Buyer == null || dbInv.BuyerId != tradeInfoDTO.Company.CompanyId) { //dbInv.Buyer = await this._db.Company.FirstOrDefaultAsync(f => f.CompanyId == tradeInfoDTO.Company.CompanyId); dbInv.Buyer = await this._companyService.CompanyMapper(dbInv.Buyer, dto.TradeInfo.Company); } if (dto.InvoiceInPLN) { dbInv.Currency = this._invoiceService._currencyList.FirstOrDefault(f => f.Name == "PLN"); } else { dbInv.Currency = this._invoiceService._currencyList.FirstOrDefault(f => f.CurrencyId == tradeInfoDTO.Price.Currency.CurrencyId); } dbInv.DateOfIssue = DateTime.Now; var extraInfo = dbInv.ExtraInfo ?? new InvoiceExtraInfo(); extraInfo.LoadNo = dto.OfferNo; if (dbInv.ExtraInfo == null) { extraInfo.InvoiceSell = dbInv; this._db.Entry(extraInfo).State = EntityState.Added; } dbInv.InvoiceNo = await this._invoiceService.GetNextInvoiceNo(dto.TradeInfo.Date); //invoice pos var price = dto.InvoiceInPLN ? tradeInfoDTO.Price.PlnValue: tradeInfoDTO.Price.Price; var brutto = Math.Round(price * 1.23, 2); var itemName = $"Usługa transportowa ({dto.Load.PostalCode} - {dto.Unload.PostalCode})"; var dbPos = new InvoicePos(); var posDTO = new InvoiceLineDTO { Brutto_value = brutto, Measurement_unit = "szt", //Name = $"Usługa transportowa", Name = itemName, Netto_value = price, Quantity = 1, Unit_price = price, Vat_rate = "23", Vat_unit_value = brutto - price, Vat_value = brutto - price }; this._invoiceService.MapperLine(dbPos, posDTO); if (dbInv.InvoicePosList == null || dbInv.InvoicePosList.Count == 0) { dbPos.InvoiceSell = dbInv; this._db.Entry(dbPos).State = EntityState.Added; } else { dbPos = dbInv.InvoicePosList.FirstOrDefault(); this._invoiceService.MapperLine(dbPos, posDTO); } var dbTotal = dbInv.InvoiceTotal ?? new InvoiceTotal(); dbTotal.TotalBrutto = brutto; dbTotal.TotalNetto = price; dbTotal.TotalTax = brutto - price; if (dbInv.InvoiceTotal == null) { dbTotal.InvoiceSell = dbInv; this._db.Entry(dbTotal).State = EntityState.Added; } var dbPaymentTerms = dbInv.PaymentTerms ?? new PaymentTerms(); this._invoiceService.MapperPaymentTerms(dbPaymentTerms, tradeInfoDTO.PaymentTerms); if (dbInv.PaymentTerms == null) { dbPaymentTerms.InvoiceSell = dbInv; this._db.Entry(dbPaymentTerms).State = EntityState.Added; } if (dbInv.RatesValuesList == null || dbInv.RatesValuesList.Count == 0) { var dbRate = new RateValue(); dbRate.BruttoValue = brutto; dbRate.NettoValue = price; dbRate.VatRate = "23"; dbRate.VatValue = brutto - price; dbRate.InvoiceSell = dbInv; this._db.Entry(dbRate).State = EntityState.Added; } else { var dbRate = dbInv.RatesValuesList.FirstOrDefault(); dbRate.BruttoValue = brutto; dbRate.NettoValue = price; dbRate.VatRate = "23"; dbRate.VatValue = brutto - price; } if (dbInv.Seller == null) { dbInv.Seller = await this._companyService.Owner(); } dbInv.SellingDate = dto.TradeInfo.Date; var dbInvTotal = dbInv.InvoiceTotal ?? new InvoiceTotal(); dbInvTotal.TotalBrutto = brutto; dbInvTotal.TotalNetto = tradeInfoDTO.Price.Price; dbInvTotal.TotalTax = brutto - tradeInfoDTO.Price.Price; if (dbInv.InvoiceTotal == null) { dbInvTotal.InvoiceSell = dbInv; this._db.Entry(dbInvTotal).State = EntityState.Added; } }