Пример #1
0
        public async Task <ActionResult <DisbursementList> > processRetrieval(
            [FromBody] List <fakeRequisitionDetails> fakeRequisitions, int id, int year, int month, int day)
        {
            Console.WriteLine(year);
            Console.WriteLine(month);
            Console.WriteLine(day);
            string time = year + "-" + month + "-" + day + " 23:59:59";

            Console.WriteLine(time);
            #region data fetching for processing
            Console.WriteLine("post");
            var allRD = await _clkService.findAllRequsitionDetailsAsync();

            var nonDeliveredRD     = allRD.Where(x => x.status != "Delivered");
            var nonAppliedRD       = nonDeliveredRD.Where(x => x.status != "Applied");
            var requisitiondetails = nonAppliedRD.Where(x => x.status != "Declined");
            var requisitions       = await _clkService.findAllRequsitionAsync();

            var stationeries = await _clkService.findAllStationeriesAsync();

            var departments = await _clkService.findAllDepartmentAsync();

            var collectionpoints = await _clkService.findAllCollectionPointAsync();

            Console.WriteLine("fetching done and starting processing");
            #endregion

            #region create new Stock Adjustment
            StockAdjustment newSA = new StockAdjustment();
            newSA.date       = DateTime.Now;
            newSA.EmployeeId = id;
            newSA.type       = "stock retrieval";
            _clkService.saveStockAdjustment(newSA);
            Console.WriteLine("created stock adjustment");
            #endregion

            #region creating necessary Disbursement List
            HashSet <Department> deptlist = new HashSet <Department>();
            foreach (fakeRequisitionDetails i in fakeRequisitions)
            {
                foreach (RequisitionDetail rd in requisitiondetails)
                {
                    if ((i.reqQty != 0) && (i.id == rd.Id))
                    {
                        var rul = await _clkService.findEmployeeByIdAsync(requisitions.Where(y => y.Id == rd.RequisitionId).FirstOrDefault().EmployeeId);

                        deptlist.Add(departments.Where(x => x.Id == rul.departmentId).FirstOrDefault());
                    }
                }
            }

            List <DisbursementList> disbursementList = new List <DisbursementList>();
            foreach (Department d in deptlist)
            {
                DisbursementList newDL = new DisbursementList();
                newDL.DepartmentId  = d.Id;
                newDL.date          = DateTime.Parse(time);
                newDL.deliveryPoint = collectionpoints.Where(x => x.Id == d.CollectionId).FirstOrDefault().collectionPoint;
                //d.Collection.collectionPoint;
                disbursementList.Add(newDL);
                _clkService.saveDisbursementList(newDL);
            }
            #endregion

            foreach (DisbursementList dl in disbursementList)
            {
                foreach (fakeRequisitionDetails i in fakeRequisitions)
                {
                    foreach (RequisitionDetail rd in requisitiondetails)
                    {
                        if ((i.reqQty != 0) && (i.id == rd.Id))
                        {
                            var currEmp = await _clkService.findEmployeeByIdAsync(requisitions.Where(y => y.Id == rd.RequisitionId).FirstOrDefault().EmployeeId);

                            if (currEmp.departmentId == dl.DepartmentId)
                            {
                                #region saving stockadjustments
                                StockAdjustmentDetail SAD = new StockAdjustmentDetail();
                                SAD.stockAdjustmentId = newSA.Id;
                                SAD.StationeryId      = rd.StationeryId;
                                SAD.discpQty          = -(i.reqQty);
                                SAD.comment           = "sent to " + departments.Where(x => x.Id == currEmp.departmentId).FirstOrDefault().deptName;
                                SAD.Status            = "Approved";
                                _clkService.saveStockAdjustmentDetail(SAD);
                                #endregion

                                #region updating stationeries item
                                foreach (Stationery s in stationeries)
                                {
                                    if (s.Id == rd.StationeryId)
                                    {
                                        s.inventoryQty -= i.reqQty;
                                        _clkService.updateStationery(s);
                                    }
                                }
                                #endregion

                                #region updating requisition detail

                                rd.rcvQty += i.reqQty;
                                Console.WriteLine($"{rd.Id},{rd.reqQty},{rd.rcvQty},{rd.StationeryId}, for the incoming {i.reqQty}");
                                _clkService.udpateRequisitionDetail(rd);
                                #endregion

                                #region creating disbursements
                                DisbursementDetail currDB = new DisbursementDetail();
                                currDB.DisbursementListId = dl.id;
                                currDB.qty = i.reqQty;
                                currDB.RequisitionDetailId = rd.Id;
                                _clkService.saveDisbursementDetail(currDB);
                                #endregion



                                Console.WriteLine("id:" + i.id + ", reqID:" + rd.RequisitionId + ", qty:" + i.reqQty);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("done");
            return(Ok(disbursementList));
        }
 public Constants.DB_STATUS Delete(StockAdjustment stockAdjustment)
 {
     throw new NotImplementedException();
 }
Пример #3
0
        public void PopulateMasterData()
        {
            localWarehouse = new Warehouse()
            {
                Name        = "Sentral Solusi Data",
                Description = "Kali Besar Jakarta",
                Code        = "LCL"
            };
            localWarehouse = _warehouseService.CreateObject(localWarehouse, _warehouseItemService, _itemService);

            Pcs = new UoM()
            {
                Name = "Pcs"
            };
            _uomService.CreateObject(Pcs);

            Boxes = new UoM()
            {
                Name = "Boxes"
            };
            _uomService.CreateObject(Boxes);

            Tubs = new UoM()
            {
                Name = "Tubs"
            };
            _uomService.CreateObject(Tubs);

            blanket1 = new Item()
            {
                ItemTypeId   = _itemTypeService.GetObjectByName("Blanket").Id,
                Name         = "Blanket1",
                Category     = "Blanket",
                Sku          = "BLK1",
                UoMId        = Pcs.Id,
                SellingPrice = 10000,
                AvgPrice     = 10000
            };

            blanket1 = _itemService.CreateObject(blanket1, _uomService, _itemTypeService, _warehouseItemService, _warehouseService, _priceMutationService, _contactGroupService);

            blanket2 = new Item()
            {
                ItemTypeId   = _itemTypeService.GetObjectByName("Blanket").Id,
                Name         = "Blanket2",
                Category     = "Blanket",
                Sku          = "BLK2",
                UoMId        = Pcs.Id,
                SellingPrice = 20000,
                AvgPrice     = 20000
            };

            blanket2 = _itemService.CreateObject(blanket2, _uomService, _itemTypeService, _warehouseItemService, _warehouseService, _priceMutationService, _contactGroupService);

            blanket3 = new Item()
            {
                ItemTypeId   = _itemTypeService.GetObjectByName("Blanket").Id,
                Name         = "Blanket3",
                Category     = "Blanket",
                Sku          = "BLK3",
                UoMId        = Pcs.Id,
                SellingPrice = 30000,
                AvgPrice     = 30000
            };

            blanket3 = _itemService.CreateObject(blanket3, _uomService, _itemTypeService, _warehouseItemService, _warehouseService, _priceMutationService, _contactGroupService);

            contact = new Contact()
            {
                Name         = "President of Indonesia",
                Address      = "Istana Negara Jl. Veteran No. 16 Jakarta Pusat",
                ContactNo    = "021 3863777",
                PIC          = "Mr. President",
                PICContactNo = "021 3863777",
                Email        = "*****@*****.**"
            };
            _contactService.CreateObject(contact, _contactGroupService);

            contact2 = new Contact()
            {
                Name         = "Wakil President of Indonesia",
                Address      = "Istana Negara Jl. Veteran No. 16 Jakarta Pusat",
                ContactNo    = "021 3863777",
                PIC          = "Mr. Wakil President",
                PICContactNo = "021 3863777",
                Email        = "*****@*****.**"
            };
            _contactService.CreateObject(contact2, _contactGroupService);

            contact3 = new Contact()
            {
                Name           = "Roma Irama",
                Address        = "Istana Negara Jl. Veteran No.20 Jakarta Pusat",
                ContactNo      = "021 5551234",
                PIC            = "Mr. King",
                PICContactNo   = "021 5551234",
                Email          = "*****@*****.**",
                ContactGroupId = group2.Id,
            };
            _contactService.CreateObject(contact3, _contactGroupService);

            cashBank = new CashBank()
            {
                Name        = "Kontan",
                Description = "Bayar kontan",
                IsBank      = false
            };
            _cashBankService.CreateObject(cashBank, _accountService);

            cashBank2 = new CashBank()
            {
                Name        = "Rekening BRI",
                Description = "Untuk cashflow",
                IsBank      = true
            };
            _cashBankService.CreateObject(cashBank2, _accountService);

            cashBankAdjustment = new CashBankAdjustment()
            {
                CashBankId     = cashBank.Id,
                Amount         = 1000000000,
                AdjustmentDate = DateTime.Today,
            };
            _cashBankAdjustmentService.CreateObject(cashBankAdjustment, _cashBankService);

            cashBankAdjustment2 = new CashBankAdjustment()
            {
                CashBankId     = cashBank2.Id,
                Amount         = 1000000000,
                AdjustmentDate = DateTime.Today,
            };
            _cashBankAdjustmentService.CreateObject(cashBankAdjustment2, _cashBankService);

            _cashBankAdjustmentService.ConfirmObject(cashBankAdjustment, DateTime.Now, _cashMutationService, _cashBankService,
                                                     _generalLedgerJournalService, _accountService, _closingService);
            _cashBankAdjustmentService.ConfirmObject(cashBankAdjustment2, DateTime.Now, _cashMutationService, _cashBankService,
                                                     _generalLedgerJournalService, _accountService, _closingService);
            StockAdjustment sa = new StockAdjustment()
            {
                AdjustmentDate = DateTime.Now,
                Code           = "SA001",
                WarehouseId    = localWarehouse.Id
            };

            _stockAdjustmentService.CreateObject(sa, _warehouseService);

            StockAdjustmentDetail sad1 = new StockAdjustmentDetail()
            {
                StockAdjustmentId = sa.Id,
                ItemId            = blanket1.Id,
                Quantity          = 100000,
                Code  = "SAD001",
                Price = 50000
            };

            _stockAdjustmentDetailService.CreateObject(sad1, _stockAdjustmentService, _itemService, _warehouseItemService);

            StockAdjustmentDetail sad2 = new StockAdjustmentDetail()
            {
                StockAdjustmentId = sa.Id,
                ItemId            = blanket2.Id,
                Quantity          = 100000,
                Code  = "SAD002",
                Price = 50000
            };

            _stockAdjustmentDetailService.CreateObject(sad2, _stockAdjustmentService, _itemService, _warehouseItemService);

            StockAdjustmentDetail sad3 = new StockAdjustmentDetail()
            {
                StockAdjustmentId = sa.Id,
                ItemId            = blanket3.Id,
                Quantity          = 100000,
                Code  = "SAD003",
                Price = 50000
            };

            _stockAdjustmentDetailService.CreateObject(sad3, _stockAdjustmentService, _itemService, _warehouseItemService);

            _stockAdjustmentService.ConfirmObject(sa, DateTime.Today, _stockAdjustmentDetailService, _stockMutationService, _itemService, _barringService,
                                                  _warehouseItemService, _generalLedgerJournalService, _accountService, _closingService);
        }
Пример #4
0
        public async Task <ActionResult <IList <DisbursementList> > > GetDisbursementDetailByDeptId([FromBody] List <fakeDisbursementDetail> fdd)
        {
            Console.WriteLine(fdd.Count());
            var incoming     = fdd;
            var incomingDDiD = fdd.Select(x => x.id);
            var incomingDDDL = fdd.Select(x => x.DisbursementListId);

            var allCP = await _clerkService.findAllCollectionPointAsync();

            var allDL = await _clerkService.findAllDisbursementListAsync();

            var currDL   = allDL.Where(x => incomingDDDL.Contains(x.id));
            var currDLPt = currDL.Select(x => x.deliveryPoint);
            var currCP   = allCP.Where(x => currDLPt.Contains(x.collectionPoint));
            var allDD    = await _clerkService.findAllDisbursementDetailAsync();

            var currDD = allDD.Where(x => incomingDDiD.Contains(x.id));
            var allRD  = await _clerkService.findAllRequsitionDetailsAsync();

            StockAdjustment SA = new StockAdjustment();

            SA.date       = DateTime.Now;
            SA.EmployeeId = currCP.FirstOrDefault().clerkId;
            SA.type       = "lost during delivery to";
            _clerkService.saveStockAdjustment(SA);


            foreach (DisbursementDetail dd in currDD)
            {
                foreach (fakeDisbursementDetail fkdd in fdd)
                {
                    if (fkdd.id == dd.id)
                    {
                        if (fkdd.qty != dd.qty)
                        {
                            RequisitionDetail rd = allRD.Where(x => x.Id == fkdd.RequisitionDetailId).FirstOrDefault();
                            rd.rcvQty -= (dd.qty - fkdd.qty);
                            _clerkService.udpateRequisitionDetail(rd);

                            StockAdjustmentDetail SAD = new StockAdjustmentDetail();
                            SAD.stockAdjustmentId = SA.Id;
                            SAD.StationeryId      = rd.StationeryId;
                            SAD.discpQty          = (dd.qty - fkdd.qty);
                            SAD.comment           = "lost during delivery";
                            SAD.Status            = "Approved";
                            _clerkService.saveStockAdjustmentDetail(SAD);

                            dd.qty = fkdd.qty;
                            _clerkService.updateDisbursementDetail(dd);
                        }
                        else
                        {
                            RequisitionDetail rd = allRD.Where(x => x.Id == fkdd.RequisitionDetailId).FirstOrDefault();
                            if (rd.rcvQty == rd.reqQty)
                            {
                                rd.status = "Delivered";
                                _clerkService.udpateRequisitionDetail(rd);
                            }
                            else if (rd.reqQty > rd.rcvQty && rd.rcvQty != 0)
                            {
                                rd.status = "Partially_Delivered";
                                _clerkService.udpateRequisitionDetail(rd);
                            }
                        }
                    }
                }
            }
            return(null);
        }