Exemple #1
0
        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;
        }
Exemple #2
0
        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;
        }
Exemple #3
0
 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();
     }
 }
Exemple #4
0
 public dtoResult SoftDelete(dtoDocument t)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public dtoResult Update(dtoDocument t)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
        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;
        }
Exemple #7
0
        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();
        }
Exemple #8
0
 public dtoResult Insert(dtoDocument t)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
        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;
        }
Exemple #10
0
 public dtoDocument Get(dtoDocument t)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
 public void SaveTransaction(dtoDocument document, List<dtoTransaction> products)
 {
     repo.SaveTransaction(document,products);
 }
Exemple #12
0
 public dtoResult SavePurchaseTransaction(dtoDocument header, List<dtoTransaction> details)
 {
     return repo.SavePurchaseTransaction(header, details);
 }