public void AddDocument(ref dtoDocument t) { var document = new tbl_document { documentNumber = t.documentNumber, transactionDate = t.transactionDate, referenceId = t.referenceId, dateCreated = DateTime.Now, createdBy = t.createdBy, documentType = t.documentType, //documentType = docType, documentId = t.documentId, branchId = t.branchId }; DBContext.tbl_document.Add(document); DBContext.SaveChanges(); t.documentId = document.documentId; }
public dtoResult SaveInvoiceTransaction(dtoDocument document, List<dtoTransaction> products) { var result = new dtoResult(); try { int docType = 0; switch (document.documentNumber.Substring(0, 2)) { //sales invoice case "SI": docType = 1; break; //sales refund case "RF": docType = 5; break; //Delivery Receipt - still sales invoice instead of 7. case "DR": docType = 1; break; //Delivery Receipt - still sales invoice instead of 8. case "OS": docType = 1; break; } document.documentType = docType; if (document.documentId == 0) { AddDocument(ref document); } else { EditDocument(document); } foreach ( var item in DBContext.tbl_transaction.ToList() .Where( d => d.documentId == document.documentId)) { var product = DBContext.tbl_product.FirstOrDefault(d => d.productId == item.productId); if (product != null) { switch (document.documentType) { case 8: case 7: case 1: product.outgoing = product.outgoing - item.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; break; case 5: product.incoming = product.incoming - item.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; break; } } DBContext.tbl_transaction.Remove(item); } if(products != null) foreach (var item in products) { //if (item.transactionId == 0) //{ item.documentId = document.documentId; switch (document.documentType) { case 8: case 7: case 1: item.transactionType = 3; break; case 5: item.transactionType = 7; break; } AddTransaction(item, document.createdBy); //} } DBContext.SaveChanges(); result.isSuccessful = true; //result.returnObj = t; } catch(Exception ex) { result.isSuccessful = false; result.errorMsg = ex.ToString(); } return result; }
public void EditDocument(dtoDocument t) { var item = DBContext.tbl_document.FirstOrDefault(d => d.documentId == t.documentId); if (item != null) { item.documentNumber = t.documentNumber; item.referenceId = t.referenceId; item.transactionDate = t.transactionDate; item.payment = t.payment; DBContext.SaveChanges(); } }
public dtoResult SoftDelete(dtoDocument t) { throw new NotImplementedException(); }
public dtoResult Update(dtoDocument t) { throw new NotImplementedException(); }
public dtoResult SavePurchaseTransaction(dtoDocument document, List<dtoTransaction> products) { var result = new dtoResult(); try { int docType = 0; switch (document.documentNumber.Substring(0, 2)) { //purchase order case "PO": docType = 2; break; //purchase return case "RT": docType = 6; break; //Delivery Receipt - still sales invoice instead of 7. case "DR": docType = 1; break; //Delivery Receipt - still sales invoice instead of 8. case "OS": docType = 1; break; } var incompletePrice = products .Where(_=>_.unitPrice ==0) .Select(_ => _.transactionId).ToList(); document.payment = incompletePrice.Count > 0 ? 0 : 1; document.documentType = docType; if (document.documentId == 0) { AddDocument(ref document); } else { EditDocument(document); } foreach ( var item in DBContext.tbl_transaction.ToList() .Where( d => d.documentId == document.documentId )) { var product = DBContext.tbl_product.FirstOrDefault(d => d.productId == item.productId); if (product != null) { //product.unitPrice = item.unitPrice; //product.incoming = product.incoming - item.quantity; //product.ending = (product.beginning + product.incoming) - product.outgoing; switch (document.documentType) { case 8: case 7: case 2: //product.unitPrice = item.unitPrice; product.incoming = product.incoming - item.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; break; case 6: //If return do not change price //product.unitPrice = item.unitPrice; product.outgoing = product.outgoing - item.quantity; product.ending = (product.beginning + product.incoming) - product.outgoing; break; } } DBContext.tbl_transaction.Remove(item); } if (products != null) foreach (var item in products) { //if (item.transactionId != 0) continue; item.documentId = document.documentId; switch (document.documentType) { case 8: case 7: case 2: item.transactionType = 1; break; case 6: item.transactionType = 6; break; } AddTransaction(item, document.createdBy); } DBContext.SaveChanges(); result.isSuccessful = true; //result.returnObj = t; } catch (Exception ex) { result.isSuccessful = false; result.errorMsg = ex.ToString(); } return result; }
public void SaveTransaction(dtoDocument document, List<dtoTransaction> products) { if (document.documentId == 0) { AddDocument(ref document); }else { EditDocument(document); } foreach (var item in DBContext.tbl_transaction.ToList().Where(d => d.documentId == document.documentId && !products.Select(t => t.transactionId).Contains(d.transactionId))) { DBContext.tbl_transaction.Remove(item); } foreach (var item in products) { if (item.transactionId == 0) { item.documentId = document.documentId; AddTransaction(item); } } DBContext.SaveChanges(); }
public dtoResult Insert(dtoDocument t) { throw new NotImplementedException(); }
public List<dtoDocument> GetPurchaseOrderByFilter(dtoDocument filter) { var poList = (from i in DBContext.tbl_document.Where(i => i.documentType == 2 && i.referenceId == filter.referenceId) join b in DBContext.tbl_supplier on i.referenceId equals b.supplierId select new dtoDocument { documentId = i.documentId, branchId = i.branchId, referenceId = i.referenceId, documentNumber = i.documentNumber, documentType = i.documentType, dateCreated = i.dateCreated, purchasePrice = 0, transactionDate = i.transactionDate, supplierCode = b.supplierCode, supplierName = b.supplierName, totalPaid = DBContext.tbl_paymentDetails.Where(d => d.documentId == i.documentId).Sum(e => e.paymentPrice) ?? 0.00M }).ToList(); foreach (var item in poList) { //DBContext.tbl_transaction.Where(x => x.documentId == x.documentId).Sum(y => (y.discountA != 0 || y.discountB != 0 || y.discountC != 0) ? ((((y.unitPrice * ((100M - (decimal)y.discountA) * 0.01M)) * ((100M - (decimal)y.discountB) * 0.01M)) * ((100M - (decimal)y.discountC) * 0.01M)) * y.quantity) : (y.unitPrice * y.quantity)), var details = DBContext.tbl_transaction.Where(x => x.documentId == item.documentId).ToList(); item.purchasePrice = details.Sum(y => (y.discountA != 0 || y.discountB != 0 || y.discountC != 0) ? ((((y.unitPrice * ((100M - (decimal)y.discountA) * 0.01M)) * ((100M - (decimal)y.discountB) * 0.01M)) * ((100M - (decimal)y.discountC) * 0.01M)) * y.quantity) : (y.unitPrice * y.quantity)); } poList = poList.Where(i => i.totalPaid < i.purchasePrice).ToList(); return poList; }
public dtoDocument Get(dtoDocument t) { throw new NotImplementedException(); }
public void SaveTransaction(dtoDocument document, List<dtoTransaction> products) { repo.SaveTransaction(document,products); }
public dtoResult SavePurchaseTransaction(dtoDocument header, List<dtoTransaction> details) { return repo.SavePurchaseTransaction(header, details); }