Exemple #1
0
        private void BtnDepositClick(object sender, EventArgs e)
        {
            if (!UserService.AllowToPerform(Resources.PermissionAddDeposit))
            {
                const string briefMsg = "អំពី​សិទ្ឋិ​ប្រើ​ប្រាស់";
                var detailMsg = Resources.MsgUserPermissionDeny;
                using (var frmMessageBox = new FrmExtendedMessageBox())
                {
                    frmMessageBox.BriefMsgStr = briefMsg;
                    frmMessageBox.DetailMsgStr = detailMsg;
                    frmMessageBox.IsCanceledOnly = true;
                    frmMessageBox.ShowDialog(this);
                    return;
                }
            }

            ScanFocusHandler();

            if (_saleItemBindingList.Count == 0)
                return;

            Visible = false;
            try
            {
                using (var frmPayment = new FrmPayment())
                {
                    frmPayment.CommonService = _commonService;
                    frmPayment.CustomerService = _customerService;
                    frmPayment.TotalAmountInt = _totalAmountInt;
                    frmPayment.IsDeposit = true;
                    if (frmPayment.ShowDialog(this) == DialogResult.OK)
                    {
                        Visible = true;
                        var depositItemList = _depositService.GetDepositItems(_saleItemBindingList);

                        _deposit = _depositService.RecordDeposit(
                            depositItemList,
                            _totalAmountInt,
                            frmPayment.AmountPaidInt,
                            frmPayment.AmountPaidRiel,
                            frmPayment.Customer,
                            string.Empty,
                            frmPayment.Customer.FkDiscountCard.DiscountPercentage,
                            false);

                        if (_deposit == null)
                            return;

                        DoActivateControls(false);
                        SetCustomerInfo(frmPayment.Customer);
                        SetInvoiceInfo(
                            _deposit.DepositNumber,
                            _deposit.AmountSoldInt,
                            _deposit.AmountPaidInt,
                            _deposit.AmountPaidRiel,
                            _deposit.AmountReturnInt);
                        InvoicePrinting(
                            _deposit.FkCustomer,
                            _deposit.DepositNumber,
                            (DateTime)_deposit.DepositDate,
                            _deposit.Discount,
                            _deposit.AmountPaidInt,
                            0,
                            0,
                            true);

                        LocalStockHandler();

                        var frmThank = new FrmThank();
                        frmThank.ShowDialog(this);
                    }
                    Visible = true;
                }
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }
        private void BtnPrintClick(object sender, EventArgs e)
        {
            if (_depositList == null)
                return;

            if (_depositList.Count == 0)
                return;

            if (dgvDeposit.CurrentRow == null)
                return;

            _deposit = _depositList[dgvDeposit.CurrentRow.Index];
            if (_deposit == null)
                return;

            _depositItemList = _depositService.GetDepositItems(_deposit.DepositId);
            var saleItemList = _saleOrderService.GetSaleItems(_depositItemList);

            var printInvoice = new PrintInvoice();
            printInvoice.ExcelInvoicePrintingHandler(
                AppContext.Counter.ReceiptPrinter,
                Application.StartupPath + @"\" + Resources.ConstDepositExcelFile,
                string.Empty,
                _deposit.FkCustomer.CustomerName,
                _deposit.FkCustomer.CustomerName,
                _deposit.DepositNumber,
                (DateTime)_deposit.DepositDate,
                _deposit.Discount,
                _deposit.AmountPaidInt,
                0,
                saleItemList,
                true);
        }
        private void BtnCancelDepositClick(object sender, EventArgs e)
        {
            var briefMsg = "អំពី​សិទ្ឋិ​ប្រើ​ប្រាស់";
            var detailMsg = Resources.MsgUserPermissionDeny;
            if (!UserService.AllowToPerform(Resources.PermissionCancelDeposit))
            {
                using (var frmMessageBox = new FrmExtendedMessageBox())
                {
                    frmMessageBox.BriefMsgStr = briefMsg;
                    frmMessageBox.DetailMsgStr = detailMsg;
                    frmMessageBox.IsCanceledOnly = true;
                    frmMessageBox.ShowDialog(this);
                    return;
                }
            }

            if (_depositList == null)
                return;

            if (_depositList.Count == 0)
                return;

            if (dgvDeposit.CurrentRow == null)
                return;

            _deposit = _depositList[dgvDeposit.CurrentRow.Index];
            if (_deposit == null)
                return;

            _depositItemList = new List<DepositItem>();
            //_DepositService.GetDepositItems(_Deposit.DepositId);

            //if (_Deposit == null)
            //    return;

            //if (_DepositItemList.Count == 0)
            //    return;

            briefMsg = "អំពីការបោះបង់";
            detailMsg = "សូម​មេត្តា​ចុច​លើ​ប៊ូតុង យល់​ព្រម ដើម្បី​បញ្ជាក់​ពី​ការ​ប្រគល់​សង​។";
            using (var frmMessageBox = new FrmExtendedMessageBox())
            {
                frmMessageBox.BriefMsgStr = briefMsg;
                frmMessageBox.DetailMsgStr = detailMsg;
                if (frmMessageBox.ShowDialog(this) != DialogResult.OK)
                    return;
            }

            _deposit.DepositDate = DateTime.Now;
            _deposit = _depositService.RecordDeposit(
                _depositItemList,
                _deposit.AmountSoldInt,
                _deposit.AmountPaidInt,
                0,
                _deposit.FkCustomer,
                _deposit.DepositNumber,
                _deposit.Discount,
                true);

            var paymentService = ServiceFactory.GenerateServiceInstance().GeneratePaymentService();
            var payment =
                new Model.Payments.Payment
                {
                    PaymentDate = _deposit.DepositDate,
                    PaymentAmount = _deposit.AmountPaidInt,
                    SalesOrderId = _deposit.DepositId,
                    CashierId = _deposit.CashierId
                };
            paymentService.ManagePayment(Resources.OperationRequestInsert, payment);

            RetrieveDataHandler();
        }
        private void BtnDeliverClick(object sender, EventArgs e)
        {
            try
            {
                if (_depositList == null)
                    return;

                if (_depositList.Count == 0)
                    return;

                if (dgvDeposit.CurrentRow == null)
                    return;

                _deposit = _depositList[dgvDeposit.CurrentRow.Index];
                if (_deposit == null)
                    return;

                var briefMsg = "អំពី​សិទ្ឋិ​ប្រើ​ប្រាស់";
                var detailMsg = Resources.MsgUserPermissionDeny;
                if (!UserService.AllowToPerform(Resources.PermissionEditDeposit))
                {
                    using (var frmMessageBox = new FrmExtendedMessageBox())
                    {
                        frmMessageBox.BriefMsgStr = briefMsg;
                        frmMessageBox.DetailMsgStr = detailMsg;
                        frmMessageBox.IsCanceledOnly = true;
                        frmMessageBox.ShowDialog(this);
                        return;
                    }
                }

                var saleOrder = _saleOrderService.GetSaleOrder(_deposit);
                if (saleOrder == null)
                    return;

                briefMsg = "អំពីការប្រគល់របស់";
                detailMsg = Resources.MsgConfirmDeliverProduct;
                using (var frmMessageBox = new FrmExtendedMessageBox())
                {
                    frmMessageBox.BriefMsgStr = briefMsg;
                    frmMessageBox.DetailMsgStr = detailMsg;
                    if(frmMessageBox.ShowDialog(this) != DialogResult.OK)
                        return;
                }

                _depositItemList = _depositService.GetDepositItems(_deposit.DepositId);
                var saleItemList = _saleOrderService.GetSaleItems(_depositItemList);

                _saleOrderService.RecordSaleOrder(
                    saleItemList,
                    saleOrder.AmountSoldInt,
                    saleOrder.AmountSoldInt - saleOrder.AmountPaidInt,
                    0,
                    0,
                    saleOrder.FkCustomer,
                    false,
                    _deposit.DepositNumber,
                    saleOrder.Discount,
                    _deposit.AmountPaidInt,
                    true);

                _deposit.AmountPaidInt += (_deposit.AmountSoldInt - _deposit.AmountPaidInt);
                _deposit.AmountReturnInt = 0f;
                _deposit.AmountReturnRiel = 0f;
                _deposit.UpdateDate = DateTime.Now;
                _depositService.UpdateDeposit(_deposit);

                var paymentService = ServiceFactory.GenerateServiceInstance().GeneratePaymentService();
                var payment =
                    new Model.Payments.Payment
                    {
                        PaymentDate = _deposit.DepositDate,
                        PaymentAmount = _deposit.AmountPaidInt,
                        SalesOrderId = _deposit.DepositId,
                        CashierId = _deposit.CashierId
                    };
                paymentService.ManagePayment(Resources.OperationRequestInsert, payment);

                RetrieveDataHandler();
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(Resources.MsgCaptionUnknownError, exception.Message);
            }
        }