Example #1
0
        private void ReceiptInvoiceDialog_Load(object sender, EventArgs e)
        {
            InitializeForm();
            LayoutAndBindingByAccess();
            LoadDecimalFormatings();
            ConstructTableColumns();
            gridViewInvoiceDetail.RowStyle     += new RowStyleEventHandler(gridInvoiceDetail_RowStyle);
            lkInvoiceType.Properties.DataSource = BLL.Settings.IsCenter
                ? ReceiptInvoiceType.GetAllInvoiceTypes()
                : ReceiptInvoiceType.GetAllInvoiceTypeByCode("INT"); //Internal for Hubs

            lkInvoiceType.EditValue = BLL.Settings.IsCenter ? -1 : ReceiptInvoiceType.InvoiceType.INTERNAL;
            lkCurrencyLCID.Properties.DataSource = Helpers.FormattingHelpers.GetCurrencyList();
            var etb = Convert.ToInt32(Helpers.FormattingHelpers.GetCurrencyList().ToTable().Select("Symbol = 'ETB'")[0]["ID"]);

            lkCurrencyLCID.EditValue = etb; //ETB is the default value

            PO Order = new PO(_orderID);

            if (_orderID != 0)
            {
                Activity act = new Activity();
                act.LoadByPrimaryKey(Order.StoreID);
                lblAccount.Text          = act.AccountName;
                lblAccountDetail.Text    = act.AccountName;
                lblSubAccount.Text       = act.SubAccountName;
                lblSubAccountDetail.Text = act.SubAccountName;
                lblActivity.Text         = act.Name;
                lblActivityDetail.Text   = act.Name;

                lblPOType.Text         = POType.GetPOTypeNameByID(Order.PurchaseType);
                lblPOTypeDetail.Text   = POType.GetPOTypeNameByID(Order.PurchaseType);
                lblPONumberDetail.Text = Order.PONumber.ToString();


                //lblInvoiceNoDetail.Text =

                var poStatus = new PurchaseOrderStatus();
                poStatus.LoadByPrimaryKey(Order.PurchaseOrderStatusID);
                lblOrderStatus.Text = poStatus.Name;

                var Mode = new Mode();
                Mode.LoadByPrimaryKey(Order.ModeID);
                lblMode.Text       = Mode.TypeName;
                lblModeDetail.Text = Mode.TypeName;

                var receiptInvoice = new ReceiptInvoice();

                receiptInvoice.LoadForPO(_orderID);

                try
                {
                    lblInvoiceNoDetail.Text = !receiptInvoice.IsColumnNull("STVOrInvoiceNo") ? receiptInvoice.STVOrInvoiceNo : "-";
                }
                catch (Exception)
                {
                    lblInvoiceNoDetail.Text = "-";
                }
                var invoiceType = new ReceiptInvoiceType();
                HeaderGroup.Text = "PO No: " + Order.PONumber;
            }

            //documentType
            var po            = new PO(_orderID);
            var documentTypes = BLL.DocumentType.GetDocumentTypesByPOType(po.PurchaseType);

            lkDocumentType.Properties.DataSource = documentTypes;

            lkDocumentType.EditValue = documentTypes.Rows.Count > 0 ? documentTypes.Rows[0]["DocumentTypeID"] : -1;

            if (_receiptInvoiceID != 0)
            {
                ReceiptInvoice rinvoice = new ReceiptInvoice(_receiptInvoiceID);
                //bind data to invoicedetail tab
                BindInvoiceDetail(rinvoice);

                lblOrderNumber.Text = rinvoice.PO.PONumber;

                lblSupplier.Text        = rinvoice.PO.Supplier.IsActive ? rinvoice.PO.Supplier.CompanyName : "";
                lblRefNo.Text           = rinvoice.PO.RefNo != "" ? rinvoice.PO.RefNo : "-";
                gridGrv.DataSource      = rinvoice.Receipts.DefaultView;
                txtInsurance.Text       = rinvoice.InsurancePolicyNo;
                txtInvoiceNumber.Text   = rinvoice.STVOrInvoiceNo;
                txtTransitNumber.Text   = rinvoice.TransitTransferNo;
                txtWayBill.Text         = rinvoice.WayBillNo;
                dtInvoiceDate.EditValue = !rinvoice.IsColumnNull("DateofEntry")
                    ? rinvoice.DateOfEntry
                    : DateTimeHelper.ServerDateTime;
                txtTotalValue.EditValue              = !rinvoice.IsColumnNull("TotalValue") ? rinvoice.TotalValue : 0;
                lkInvoiceType.EditValue              = !rinvoice.IsColumnNull("InvoiceTypeID") ? rinvoice.InvoiceTypeID : 0;
                txtInvoiceAirFreight.EditValue       = !rinvoice.IsColumnNull("AirFreight") ? rinvoice.AirFreight : 0;
                txtInvoiceSeaFreight.EditValue       = !rinvoice.IsColumnNull("SeaFreight") ? rinvoice.SeaFreight : 0;
                txtInvoiceInlandFreight.EditValue    = !rinvoice.IsColumnNull("InlandFreight") ? rinvoice.InlandFreight : 0;
                txtInvoiceCustomDutyTax.EditValue    = !rinvoice.IsColumnNull("CustomDutyTax") ? rinvoice.CustomDutyTax : 0;
                txtInvoiceCBEServiceCharge.EditValue = !rinvoice.IsColumnNull("CBE") ? rinvoice.CBE : 0;
                txtExchangeRate.EditValue            = !rinvoice.IsColumnNull("ExchangeRate") ? rinvoice.ExchangeRate : 1;
                lkCurrencyLCID.EditValue             = _currency = !rinvoice.IsColumnNull("LCID") ? rinvoice.LCID : 0;
                lkDocumentType.EditValue             = !rinvoice.IsColumnNull("DocumentTypeID") ? rinvoice.DocumentTypeID : -1;
                DisableEditDependingOnSetting();
                var activity = new Activity();
                activity.LoadByPrimaryKey(rinvoice.ActivityID);
                if (activity.IsHealthProgram())
                {
                    txtInvoiceCustomDutyTax.EditValue = 0;
                    txtInvoiceCustomDutyTax.Enabled   = false;
                }

                // var receiptINvoice = new ReceiptInvoice();
                // receiptINvoice.LoadForPO(_orderID);
                lblInvoiceNoDetail.Text   = rinvoice.STVOrInvoiceNo.ToString();
                lblInvoiceTypeDetail.Text = lkInvoiceType.Text;
            }
            else
            {
                PO PO = new PO(_orderID);
                lblOrderNumber.Text = PO.PONumber;

                BindInvoiceDetailByPO(PO.ID);

                lblSupplier.Text         = PO.Supplier.IsActive ? PO.Supplier.CompanyName : "_";
                lkCurrencyLCID.EditValue = 1118; //ETB is the dafault
                lblRefNo.Text            = PO.RefNo != "" ? PO.RefNo : "-";

                if (PO.StoreID != null)
                {
                    var activity = new Activity();
                    activity.LoadByPrimaryKey(po.StoreID);
                    if (activity.IsHealthProgram())
                    {
                        txtInvoiceCustomDutyTax.EditValue = 0;
                        txtInvoiceCustomDutyTax.Enabled   = false;
                    }
                }
                layoutGoodsReceived.Enabled = false;
            }
            //gridViewInvoiceDetail.ValidateRow += GridViewInvoiceDetailOnValidateRow;
        }
        private void gridOrderView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e != null && e.PrevFocusedRowHandle < -1)
            {
                return;
            }

            if (gridOrderView.GetFocusedDataRow() != null)
            {
                var dr = gridOrderView.GetFocusedDataRow();

                int    OrderID = Convert.ToInt32(dr["ID"]);
                string sharps  = Helpers.FormattingHelpers.GetNumberFormatting();
                Order = new PO(OrderID);
                RefreshInvoice();
                RefreshPoDetail();
                // Layout  ... Show the damn correct layout

                // Hide the empty layout
                LayoutEmptyDetails.Visibility        = LayoutVisibility.Never;
                LayoutSelectedOrderDetail.Visibility = LayoutVisibility.Always;

                int Currency = 0x0409;
                if (!Order.IsColumnNull("LCID"))
                {
                    Currency = Order.LCID;
                }

                if (!string.IsNullOrEmpty(Order.s_PurchaseType))
                {
                    PurchaseTypes = POType.GetAllPOTypes().Find(t => t.ID == Order.PurchaseType);
                }
                string  space = "";
                DataRow dar   = gridInvoiceView.GetFocusedDataRow();
                HeaderGroup.Text = "PO No: " + dr["OrderNumber"].ToString();
                if (dar != null)
                {
                    HeaderGroup.Text = HeaderGroup.Text + space.PadRight(160) + "Invoice No: " + gridInvoiceView.GetFocusedDataRow()["STVOrInvoiceNo"];
                }

                // lblOrderType.Text = PurchaseTypes != null ?  string.Format("{0} : {1}" ,PurchaseTypes.Group , PurchaseTypes.Name) : "";
                lblPONumber.Text   = Order.PONumber;
                lblTotalValue.Text = Order.TotalValue.ToString(Helpers.FormattingHelpers.GetCurrencyFormatByLCID(Currency));
                lblInsurance.Text  = Order.Insurance.ToString(Helpers.FormattingHelpers.GetBirrFormatting());
                lblNBE.Text        = Order.NBE.ToString(Helpers.FormattingHelpers.GetBirrFormatting());
                lblSupplier.Text   = Order.Supplier.CompanyName;
                lblShipper.Text    = String.IsNullOrEmpty(Order.ShippingSite) ? "-" : Order.ShippingSite;
                lblLetterNo.Text   = String.IsNullOrEmpty(Order.LetterNo) ? "-" : Order.LetterNo;
                lblPOType.Text     = dr["Name"].ToString();

                var PaymentType = new PaymentType();
                PaymentType.LoadByPrimaryKey(Order.PaymentTypeID);
                lblPaymentType.Text = String.IsNullOrEmpty(PaymentType.Name) ? "-" : PaymentType.Name;

                var User = new User();
                User.LoadByPrimaryKey(Order.SavedbyUserID);
                lblPOBy.Text = String.IsNullOrEmpty(User.FullName) ? "-" : User.FullName;

                if (!Order.IsColumnNull("ModeID"))
                {
                    var Mode = new Mode();
                    Mode.LoadByPrimaryKey(Order.ModeID);
                    lblMode.Text = Mode.TypeName;
                }
                else
                {
                    lblMode.Text = "-";
                }



                if (!Order.IsColumnNull("PurchaseOrderStatusID"))
                {
                    var poStatus = new PurchaseOrderStatus();
                    poStatus.LoadByPrimaryKey(Order.PurchaseOrderStatusID);
                    lblPOStatus.Text = poStatus.Name;
                }


                chkboxIsElectronic.Checked = Order.IsElectronic;
                lblOrderDate.Text          = Order.PODate.ToShortDateString();
                lblSyncDate.Text           = Order.ModifiedDate == DateTime.MinValue ? "NA" :  Order.ModifiedDate.ToString(CultureInfo.InvariantCulture);

                if (!Order.IsColumnNull("StoreID"))
                {
                    Activity act = new Activity();
                    act.LoadByPrimaryKey(Order.StoreID);
                    lblAccount.Text    = act.AccountName;
                    lblSubAccount.Text = act.SubAccountName;
                    lblActivity.Text   = act.Name;
                }
                else
                {
                    lblAccount.Text = lblSubAccount.Text = lblActivity.Text = "-";
                }

                lblRefNo.Text          = String.IsNullOrEmpty(Order.RefNo) ? "-" : Order.RefNo;
                lblRemainingValue.Text = Order.Remaining.ToString(Helpers.FormattingHelpers.GetCurrencyFormatByLCID(Currency));
                if (BLL.Settings.UseNewUserManagement && this.HasPermission("Add-Invoice"))
                {
                    btnAddInvoice.Enabled = true;
                }
                else if (BLL.Settings.UseNewUserManagement)
                {
                    btnAddInvoice.Enabled = false;
                }

                btnAddInvoice.Enabled = btnEditOrder.Enabled = btnAddOrderDetail.Enabled = !Order.IsElectronic;

                if (Order.IsElectronic)
                {
                    grdPoDetail.Enabled = false;
                    gridInvoice.Enabled = false;
                }
                else
                {
                    grdPoDetail.Enabled = true;
                    gridInvoice.Enabled = true;
                }

                //purchse order details
                grdPoDetail.DataSource = Order.PurchaseOrderDetail.DefaultView;
            }
            else
            {
                // Hide the empty layout
                LayoutEmptyDetails.Visibility        = LayoutVisibility.Always;
                LayoutSelectedOrderDetail.Visibility = LayoutVisibility.Never;
            }
        }