public static List <PurchaseOrderDetails> GetOrderDetailsBySupplier()
        {
            List <PurchaseOrderDetails> pos = AnalyticsDAO.GetOrderDetailsBySupplier();

            List <long> itemIds = new List <long>();

            foreach (var po in pos)
            {
                itemIds.Add(po.ItemId);
            }
            List <PriceList> priceLists = PriceListService.GetPriceListByItemIds(itemIds);

            //To get the unit price paid for the order, which may not have been provided by main supplier for that item
            //This is to calculate the total amount paid for the chart
            for (int i = 0; i < priceLists.Count; i++)
            {
                if (pos[i].SupplierId == priceLists[i].Supplier1Id)
                {
                    pos[i].UnitPricePaid = priceLists[i].Supplier1UnitPrice;
                }
                else if (pos[i].SupplierId == priceLists[i].Supplier2Id)
                {
                    pos[i].UnitPricePaid = priceLists[i].Supplier2UnitPrice;
                }
                else if (pos[i].SupplierId == priceLists[i].Supplier3Id)
                {
                    pos[i].UnitPricePaid = priceLists[i].Supplier3UnitPrice;
                }
            }
            return(pos);
        }
Example #2
0
        private void UpdateChargeBack(long listId)
        {
            /* Move the following code to RestRepresentativeController*/
            ////Attention: DisbursementList can only disburse once, date for that list is not null

            ///*The following code is for ChargeBack table*/
            ////By the time disburse item, calculate the amount of this list, update ChargeBack table

            DisbursementList disbursementList = DisbursementListService.GetDisbursementListByListId(listId);
            List <DisbursementListDetails> disbursementListDetails = DisbursementListDetailsDAO.ViewDetails(listId);

            foreach (DisbursementListDetails details in disbursementListDetails)
            {
                PriceList priceList = PriceListService.GetPriceListByItemId(details.Item.ItemId);
                double    price     = 0;
                if (priceList != null)
                {
                    price = priceList.Supplier1UnitPrice;
                }

                double amount = price * details.Quantity;
                ChargeBackService.UpdateChargeBackData(amount, disbursementList);

                ///*The following code is for StockCard table*/
                ////By the time disburse item, update StockCard table with itemId, deptId and date, souceType = 2

                int balance = CatalogueService.GetCatalogueById(details.Item.ItemId).StockLevel - details.Quantity;
                StockCardService.CreateStockCardFromDisburse(details, disbursementList, balance);
                StockDAO.UpdateWithReduceInventoryStockById(details.Item.ItemId, details.Quantity);

                ////following code will update and close requisitions
                int disbursedAmount             = details.Quantity;
                List <Requisition> requisitions = RequisitionDAO.GetOutstandingRequisitionsAndDetailsByDeptIdAndItemId(disbursementList.Department.DeptId, details.Item.ItemId, listId); //will get those status assigned/partially completed(assigned)

                foreach (var requisition in requisitions)
                {
                    if (requisition.RequisitionDetail.Balance <= disbursedAmount)                                     // if the balance is less than what was disbursed
                    {
                        RequisitionDetailsDAO.UpdateBalanceAmount(requisition.ReqId, details.Item.ItemId, 0);         //change balance to 0

                        if (RequisitionDetailsDAO.GetRemainingRequisitionDetailsByReqId(requisition.ReqId).Count > 0) //will get those the remaining amounts !=0 if
                        {
                            RequisitionDAO.UpdateStatus(requisition.ReqId, "Partially Completed");
                        }
                        else
                        {
                            RequisitionDAO.UpdateStatus(requisition.ReqId, "Completed");
                        }
                        disbursedAmount -= requisition.RequisitionDetail.Balance; // minusing the balance from what was disbursed
                    }
                    else// when the balance amount is more than the remainder of the disbursed amount
                    {
                        RequisitionDetailsDAO.UpdateBalanceAmount(requisition.ReqId, details.Item.ItemId, disbursedAmount);// change balance to remainder of disbursed amount

                        RequisitionDAO.UpdateStatus(requisition.ReqId, "Partially Completed");

                        break;//break out of for loop when disbursed amount become 0
                    }
                }
            }
        }