Exemplo n.º 1
0
        public ActionResult InsertBill(TTransDet viewModel, FormCollection formCollection, string transId)
        {
            //_tTransDetRepository.DbContext.BeginTransaction();
            TTrans trans = _tTransRepository.Get(transId);

            UpdateNumericData(viewModel, formCollection);
            TTransDet transDetToInsert = new TTransDet(trans);
            MEmployee emp    = _mEmployeeRepository.Get(formCollection["EmployeeId"]);
            MPacket   packet = _mPacketRepository.Get(formCollection["PacketId"]);

            TransferFormValuesTo(transDetToInsert, viewModel);
            transDetToInsert.SetAssignedIdTo(Guid.NewGuid().ToString());
            transDetToInsert.PacketId   = packet;
            transDetToInsert.EmployeeId = emp;

            transDetToInsert.TransDetCommissionService = CalculateCommission(emp, packet, transDetToInsert.TransDetTotal);

            transDetToInsert.CreatedDate = DateTime.Now;
            transDetToInsert.CreatedBy   = User.Identity.Name;
            transDetToInsert.DataStatus  = EnumDataStatus.New.ToString();
            //_tTransDetRepository.Save(transDetToInsert);
            //try
            //{
            //    _tTransDetRepository.DbContext.CommitTransaction();
            //    TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            //    return Content("success");
            //}
            //catch (Exception ex)
            //{
            //    _tTransDetRepository.DbContext.RollbackTransaction();
            //    TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed;
            //    return Content(ex.Message);
            //}

            //save temporary to session, then display transdetitem form
            Session[CONST_TRANSDET] = transDetToInsert;
            var e = new
            {
                transDetToInsert.Id,
                PacketId = transDetToInsert.PacketId.Id,
                transDetToInsert.TransDetQty
            };

            return(Json(e, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        private void SaveTransaction(TTrans Trans, FormCollection formCollection, bool addStock, bool calculateStock, bool isEdit)
        {
            if (isEdit)
            {
                if (ListDeleteDetailTrans != null)
                {
                    if (ListDeleteDetailTrans.Count > 0)
                    {
                        DeleteTransactionDetail(Trans, addStock, calculateStock, ListDeleteDetailTrans.ToArray());
                    }
                }
            }


            Trans.TransDets.Clear();

            //save stock card

            TTransDet detToInsert;
            decimal   total = 0;
            IList <TransDetViewModel> listDetToSave = new List <TransDetViewModel>();
            TransDetViewModel         detToSave     = new TransDetViewModel();

            foreach (TransDetViewModel det in ListDetTrans)
            {
                detToSave       = new TransDetViewModel();
                detToSave.IsNew = det.IsNew;

                if (det.IsNew)
                {
                    detToInsert = new TTransDet(Trans);
                    detToInsert.SetAssignedIdTo(Guid.NewGuid().ToString());
                    detToInsert.ItemId        = det.TransDet.ItemId;
                    detToInsert.ItemUomId     = det.TransDet.ItemUomId;
                    detToInsert.TransDetQty   = det.TransDet.TransDetQty;
                    detToInsert.TransDetPrice = det.TransDet.TransDetPrice;
                    detToInsert.TransDetDisc  = det.TransDet.TransDetDisc;
                    detToInsert.TransDetTotal = det.TransDet.TransDetTotal;
                    detToInsert.CreatedBy     = User.Identity.Name;
                    detToInsert.CreatedDate   = DateTime.Now;
                    detToInsert.DataStatus    = Enums.EnumDataStatus.New.ToString();
                    Trans.TransDets.Add(detToInsert);

                    detToSave.TransDet = detToInsert;
                }
                else
                {
                    detToSave.TransDet = det.TransDet;
                }
                listDetToSave.Add(detToSave);
                total += det.TransDet.TransDetTotal.HasValue ? det.TransDet.TransDetTotal.Value : 0;
            }
            Trans.TransSubTotal = total;
            if (isEdit)
            {
                _tTransRepository.Update(Trans);
            }
            else
            {
                _tTransRepository.Save(Trans);
            }
            //_tTransRepository.DbContext.CommitTransaction();

            //_tTransRepository.DbContext.BeginTransaction();
            if (calculateStock)
            {
                decimal totalHpp = 0;
                foreach (TransDetViewModel det in listDetToSave)
                {
                    if (det.IsNew)
                    {
                        //save stock
                        if (Trans.TransStatus.Equals(EnumTransactionStatus.Mutation.ToString()))
                        {
                            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.TransDet.ItemId, det.TransDet.TransDetQty, false, Trans.WarehouseId);
                            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.TransDet.ItemId, det.TransDet.TransDetQty, true, Trans.WarehouseIdTo);

                            //still to do, for mutation, price of stock must recalculate per stock,
                            //sum hpp for each stock for stock out
                            totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.TransDet.ItemId, det.TransDet.TransDetPrice, det.TransDet.TransDetQty, det.TransDet, false, Trans.WarehouseId);
                            UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.TransDet.ItemId, det.TransDet.TransDetPrice, det.TransDet.TransDetQty, det.TransDet, true, Trans.WarehouseIdTo);
                        }
                        else
                        {
                            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.TransDet.ItemId, det.TransDet.TransDetQty, addStock, Trans.WarehouseId);

                            //sum hpp for each stock
                            totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.TransDet.ItemId, det.TransDet.TransDetPrice, det.TransDet.TransDetQty, det.TransDet, addStock, Trans.WarehouseId);
                        }
                    }
                    else
                    {
                        //get HPP from existing detail
                        // totalHpp +=
                    }
                }
                ////save journal
                //SaveJournal(Trans, totalHpp);
            }
        }
Exemplo n.º 3
0
        private ActionResult SaveTransaction(TTrans Trans, FormCollection formCollection)
        {
            _tTransRepository.DbContext.BeginTransaction();
            if (Trans == null)
            {
                Trans = new TTrans();
            }
            Trans.SetAssignedIdTo(formCollection["Trans.Id"]);
            Trans.WarehouseId = _mWarehouseRepository.Get(formCollection["Trans.WarehouseId"]);
            if (!string.IsNullOrEmpty(formCollection["Trans.WarehouseIdTo"]))
            {
                Trans.WarehouseIdTo = _mWarehouseRepository.Get(formCollection["Trans.WarehouseIdTo"]);
            }
            Trans.CreatedDate = DateTime.Now;
            Trans.CreatedBy   = User.Identity.Name;
            Trans.DataStatus  = Enums.EnumDataStatus.New.ToString();

            Trans.TransDets.Clear();

            //save stock card
            bool addStock                = true;
            bool calculateStock          = false;
            EnumTransactionStatus status = (EnumTransactionStatus)Enum.Parse(typeof(EnumTransactionStatus), Trans.TransStatus);

            TransactionFormViewModel.GetIsCalculateStock(status, out addStock, out calculateStock);


            TTransDet         detToInsert;
            IList <TTransDet> listDet = new List <TTransDet>();
            decimal           total   = 0;

            foreach (TTransDet det in ListDetTrans)
            {
                detToInsert = new TTransDet(Trans);
                detToInsert.SetAssignedIdTo(Guid.NewGuid().ToString());
                detToInsert.ItemId        = det.ItemId;
                detToInsert.ItemUomId     = det.ItemUomId;
                detToInsert.TransDetQty   = det.TransDetQty;
                detToInsert.TransDetPrice = det.TransDetPrice;
                detToInsert.TransDetDisc  = det.TransDetDisc;
                detToInsert.TransDetTotal = det.TransDetTotal;
                detToInsert.CreatedBy     = User.Identity.Name;
                detToInsert.CreatedDate   = DateTime.Now;
                detToInsert.DataStatus    = Enums.EnumDataStatus.New.ToString();
                Trans.TransDets.Add(detToInsert);
                total += det.TransDetTotal.HasValue ? det.TransDetTotal.Value : 0;
                listDet.Add(detToInsert);
            }
            Trans.TransSubTotal = total;
            _tTransRepository.Save(Trans);
            //_tTransRepository.DbContext.CommitTransaction();

            //_tStockCardRepository.DbContext.BeginTransaction();
            if (calculateStock)
            {
                decimal totalHpp = 0;
                foreach (TTransDet det in listDet)
                {
                    //save stock
                    if (Trans.TransStatus.Equals(EnumTransactionStatus.Mutation.ToString()))
                    {
                        SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, false, Trans.WarehouseId);
                        SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, true, Trans.WarehouseIdTo);

                        //still to do, for mutation, price of stock must recalculate per stock,
                        //sum hpp for each stock for stock out
                        totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, false, Trans.WarehouseId);
                        UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, true, Trans.WarehouseIdTo);
                    }
                    else
                    {
                        SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, addStock, Trans.WarehouseId);

                        //sum hpp for each stock
                        totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, addStock, Trans.WarehouseId);
                    }
                }
                //UPDATE  20150629 : no linked to accounting
                ////save journal
                //SaveJournal(Trans, totalHpp);
            }


            try
            {
                _tTransRepository.DbContext.CommitTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            }
            catch (Exception)
            {
                _tTransRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed;
            }
            //if (!Trans.TransStatus.Equals(EnumTransactionStatus.PurchaseOrder.ToString()))
            //{
            //    return RedirectToAction(Trans.TransStatus.ToString());
            //}
            //return RedirectToAction("Index");
            return(View("Status"));
        }
Exemplo n.º 4
0
        public ActionResult InsertBill(TTransDet viewModel, FormCollection formCollection, string transId)
        {
            _tTransDetRepository.DbContext.BeginTransaction();
            TTrans trans = _tTransRepository.Get(transId);

            UpdateNumericData(viewModel, formCollection);
            TTransDet transDetToInsert = new TTransDet(trans);
            MAction   action           = _mActionRepository.Get(formCollection["ActionId"]);

            TransferFormValuesTo(transDetToInsert, viewModel);
            transDetToInsert.SetAssignedIdTo(Guid.NewGuid().ToString());
            transDetToInsert.ActionId = action;

            //transDetToInsert.TransDetCommissionService = CalculateCommission(emp, packet, transDetToInsert.TransDetTotal);

            transDetToInsert.CreatedDate = DateTime.Now;
            transDetToInsert.CreatedBy   = User.Identity.Name;
            transDetToInsert.DataStatus  = EnumDataStatus.New.ToString();
            _tTransDetRepository.Save(transDetToInsert);

            //save trans detail item
            SaveTransDetailItem(transDetToInsert);

            //save commission for doctor
            if (!string.IsNullOrEmpty(formCollection["DrId"]))
            {
                SaveCommission(transDetToInsert, action.ActionComponentDoctor, (formCollection["DrId"]), EnumCommissionPeople.Doctor);
            }

            //save commission for terapist
            if (!string.IsNullOrEmpty(formCollection["TherapistId"]))
            {
                SaveCommission(transDetToInsert, action.ActionComponentTherapist, (formCollection["TherapistId"]), EnumCommissionPeople.Therapist);
            }
            //save commission for Medician
            if (!string.IsNullOrEmpty(formCollection["MedicianId"]))
            {
                SaveCommission(transDetToInsert, action.ActionComponentMedician, (formCollection["MedicianId"]), EnumCommissionPeople.Medician);
            }
            try
            {
                _tTransDetRepository.DbContext.CommitTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
                return(Content("Tindakan berhasil disimpan"));
            }
            catch (Exception ex)
            {
                _tTransDetRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed;
                return(Content(ex.Message));
            }

            ////save temporary to session, then display transdetitem form
            //Session[CONST_TRANSDET] = transDetToInsert;
            var e = new
            {
                transDetToInsert.Id,
                PacketId = transDetToInsert.ActionId.Id,
                transDetToInsert.TransDetQty
            };

            return(Json(e, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        private ActionResult SaveTransaction(TTrans Trans, FormCollection formCollection)
        {
            try
            {
                _tTransRepository.DbContext.BeginTransaction();
                if (Trans == null)
                {
                    Trans = new TTrans();
                }
                Trans.SetAssignedIdTo(formCollection["Trans.Id"]);
                if (!string.IsNullOrEmpty(formCollection["Trans.WarehouseId"]))
                {
                    Trans.WarehouseId = _mWarehouseRepository.Get(formCollection["Trans.WarehouseId"]);
                }
                if (!string.IsNullOrEmpty(formCollection["Trans.WarehouseIdTo"]))
                {
                    Trans.WarehouseIdTo = _mWarehouseRepository.Get(formCollection["Trans.WarehouseIdTo"]);
                }
                if (!string.IsNullOrEmpty(formCollection["EmployeeId"]))
                {
                    Trans.EmployeeId = _mEmployeeRepository.Get(formCollection["EmployeeId"]);
                }
                Trans.CreatedDate = DateTime.Now;
                Trans.CreatedBy   = User.Identity.Name;
                Trans.DataStatus  = Enums.EnumDataStatus.New.ToString();

                Trans.TransDets.Clear();

                ////save stock card
                //bool addStock = true;
                //bool calculateStock = false;
                //EnumTransactionStatus status = (EnumTransactionStatus)Enum.Parse(typeof(EnumTransactionStatus), Trans.TransStatus);
                //TransactionFormViewModel.GetIsCalculateStock(status, out addStock, out calculateStock);

                TTransDet detToInsert;
                //IList<TTransDet> listDet = new List<TTransDet>();
                decimal total = 0;
                foreach (TTransDet det in ListDetTrans)
                {
                    detToInsert = new TTransDet(Trans);
                    detToInsert.SetAssignedIdTo(Guid.NewGuid().ToString());
                    detToInsert.ItemId        = det.ItemId;
                    detToInsert.ItemUomId     = det.ItemUomId;
                    detToInsert.TransDetQty   = det.TransDetQty;
                    detToInsert.TransDetPrice = det.TransDetPrice;
                    detToInsert.TransDetDisc  = det.TransDetDisc;
                    detToInsert.TransDetTotal = det.TransDetTotal;
                    detToInsert.CreatedBy     = User.Identity.Name;
                    detToInsert.CreatedDate   = DateTime.Now;
                    detToInsert.DataStatus    = Enums.EnumDataStatus.New.ToString();

                    detToInsert.EmployeeId = Trans.EmployeeId;

                    detToInsert.TransDetCommissionProduct = CalculateCommission(Trans.EmployeeId, det.ItemId, detToInsert.TransDetTotal);
                    Trans.TransDets.Add(detToInsert);
                    total += det.TransDetTotal.HasValue ? det.TransDetTotal.Value : 0;
                    //listDet.Add(detToInsert);
                }
                Trans.TransSubTotal = total;
                _tTransRepository.Save(Trans);


                TTransRoom troom = new TTransRoom();
                troom.SetAssignedIdTo(formCollection["Trans.Id"]);
                troom.RoomStatus = EnumTransRoomStatus.Paid.ToString();
                if (!string.IsNullOrEmpty(formCollection["hidpaymentCash"]))
                {
                    string paymentCash = formCollection["hidpaymentCash"].Replace(",", "");
                    troom.RoomCashPaid = Convert.ToDecimal(paymentCash);
                }
                if (!string.IsNullOrEmpty(formCollection["hidpaymentVoucher"]))
                {
                    string paymentVoucher = formCollection["hidpaymentVoucher"].Replace(",", "");
                    troom.RoomVoucherPaid = Convert.ToDecimal(paymentVoucher);
                }
                if (!string.IsNullOrEmpty(formCollection["hidpaymentCreditCard"]))
                {
                    string paymentCreditCard = formCollection["hidpaymentCreditCard"].Replace(",", "");
                    troom.RoomCreditPaid = Convert.ToDecimal(paymentCreditCard);
                }
                troom.RoomOutDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} {1:HH:mm}", Trans.TransDate, DateTime.Now));
                troom.CreatedBy   = User.Identity.Name;
                troom.CreatedDate = DateTime.Now;
                troom.DataStatus  = EnumDataStatus.New.ToString();
                _tTransRoomRepository.Save(troom);


                _tTransRepository.DbContext.CommitTransaction();

                ////_tStockCardRepository.DbContext.BeginTransaction();
                //if (calculateStock)
                //{
                //    decimal totalHpp = 0;
                //    foreach (TTransDet det in listDet)
                //    {
                //        //save stock
                //        if (Trans.TransStatus.Equals(EnumTransactionStatus.Mutation.ToString()))
                //        {
                //            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, false, Trans.WarehouseId);
                //            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, true, Trans.WarehouseIdTo);

                //            //still to do, for mutation, price of stock must recalculate per stock,
                //            //sum hpp for each stock for stock out
                //            totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, false, Trans.WarehouseId);
                //            UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, true, Trans.WarehouseIdTo);
                //        }
                //        else
                //        {
                //            SaveStockItem(Trans.TransDate, Trans.TransDesc, det.ItemId, det.TransDetQty, addStock, Trans.WarehouseId);

                //            //sum hpp for each stock
                //            totalHpp += UpdateStock(Trans.TransDate, Trans.TransDesc, Trans.TransStatus, det.ItemId, det.TransDetPrice, det.TransDetQty, det, addStock, Trans.WarehouseId);
                //        }
                //    }
                //    //save journal
                //    SaveJournal(Trans, totalHpp);
                //}


                //_tTransRepository.DbContext.CommitTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            }
            catch (Exception)
            {
                _tTransRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed;
            }
            //if (!Trans.TransStatus.Equals(EnumTransactionStatus.PurchaseOrder.ToString()))
            //{
            //    return RedirectToAction(Trans.TransStatus.ToString());
            //}
            //return RedirectToAction("Index");
            return(View("Status"));
        }