private void btnPrintSTV_Click(object sender, EventArgs e)
        {
            DataRow dataView = gridDeliveryNoteView.GetFocusedDataRow();
            if (dataView != null)
            {
                int stvlogID = Convert.ToInt32(dataView["ID"]);

                DataView dv = PickList.GetPickedItemsOnSTV( stvlogID,false );

                if (dv.Count > 0 && ValidateAndFixDeliveryNoteHasBeenProperlyPrice(dv))
                {
                    LogIssues logScreen = new LogIssues();

                    BLL.Issue stvLog = new BLL.Issue();
                    stvLog.LoadByPrimaryKey(stvlogID);

                    PickList pickList = new PickList();
                    pickList.LoadByPrimaryKey(stvLog.PickListID);
                    XtraReport xtraReport;
                    PrintDialog printDialog = new PrintDialog();
                    if(printDialog.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }

                    MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

                    try
                    {
                     mgr.BeginTransaction();

                       xtraReport = logScreen.RePrintSTV(dv, pickList.OrderID, pickList,stvlogID,true);
                        stvLog.HasDeliveryNoteBeenConverted = true;
                        stvLog.Save();
                     mgr.CommitTransaction();
                    }
                    catch (Exception exception)
                    {
                        mgr.RollbackTransaction();
                        XtraMessageBox.Show("Print Problem:" + exception.Message , "Print Problem",MessageBoxButtons.OK,MessageBoxIcon.Error);
                        throw;
                    }
                    if(xtraReport!= null)
                    {
                        xtraReport.Print(printDialog.PrinterSettings.PrinterName);
                    }
                    lkStore_EditValueChanged(null, null);
                }else
                {
                    XtraMessageBox.Show(
                        "You cannot print this STV because price has not been set for all item. Please try again");
                }

            }
        }
        /// <summary>
        /// Gets the picked items on STV.
        /// </summary>
        /// <param name="stvlogID">The stvlog ID.</param>
        /// <returns></returns>
        public static DataView GetPickedItemsOnSTV(int stvlogID, bool includeDeleted)
        {
            Issue stvLog = new Issue();
            stvLog.LoadByPrimaryKey(stvlogID);

            PickList pickList = new PickList();
            pickList.LoadByPrimaryKey(stvLog.PickListID);

            DataView dv = pickList.GetPickedOrderDetailForOrder(stvlogID, includeDeleted);
            dv.RowFilter = "STVID = " + stvlogID;
            return dv;
        }
Example #3
0
        /// <summary>
        /// Gets the picked items on STV.
        /// </summary>
        /// <param name="stvlogID">The stvlog ID.</param>
        /// <returns></returns>
        public static DataView GetPickedItemsOnSTV(int stvlogID, bool includeDeleted)
        {
            Issue stvLog = new Issue();

            stvLog.LoadByPrimaryKey(stvlogID);

            PickList pickList = new PickList();

            pickList.LoadByPrimaryKey(stvLog.PickListID);

            DataView dv = pickList.GetPickedOrderDetailForOrder(stvlogID, includeDeleted);

            dv.RowFilter = "STVID = " + stvlogID;
            return(dv);
        }
        /// <summary>
        /// Handles the FocusedRowChanged event of the gridViewReferences control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs" /> instance containing the event data.</param>
        private void gridViewReferences_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e != null && e.PrevFocusedRowHandle < -1)
                return;

            dtDate.Value = DateTimeHelper.ServerDateTime;
            _reprintId = null;
            DataRow dr = gridViewReferences.GetFocusedDataRow();
            if (dr == null)
            {
                return;
            }

            string[] referenceNo = new string[2];
            referenceNo[0] = dr["RefNo"].ToString();

            if (Convert.ToBoolean(dr["isConvertedDN"]))
            {
                _isConvertedDn = true;
                _stvLogIdChosen = (int?)dr["IsReprintOf"];
            }
            else if (dr != null && dr["ID"] != DBNull.Value)
            {
                _isConvertedDn = false;
                _stvLogIdChosen = (int?)dr["ID"];
            }

            UpdateReprintedNumbers(dr);

            // Enable and disable STV reprint
            // STV SHouldn't be reprinted off a reprint.
            if (dr["IsReprintOf"] != DBNull.Value && !Convert.ToBoolean(dr["isConvertedDN"]))
            {
                btnExport.Enabled = btnReprint.Enabled = false;
                var permission = (BLL.Settings.UseNewUserManagement) ? this.HasPermission("Print") : true;
                btnPrint.Enabled = permission;
                _reprintId = _stvLogIdChosen;
                _stvLogIdChosen = Convert.ToInt32(dr["IsReprintOf"]);
            }
            else if (dr["IsDeliveryNote"] != DBNull.Value && Convert.ToBoolean(dr["IsDeliveryNote"]))
            {
                btnExport.Enabled = false;
                btnReprint.Enabled = (BLL.Settings.UseNewUserManagement) ? this.HasPermission("Re-Print") : true;
                btnPrint.Enabled = false;
            }
            else
            {
                btnPrint.Enabled = this.HasPermission("Print");
                btnReprint.Enabled = this.HasPermission("Re-Print");
                btnExport.Enabled = this.HasPermission("Export");
            }

            if (_stvLogIdChosen != null)
            {
                Issue log = new Issue();
                log.LoadByPrimaryKey(_stvLogIdChosen.Value);

                Institution rus = new Institution();
                IssueDoc iss = new IssueDoc();
                if (!log.IsColumnNull("ReceivingUnitID"))
                {
                    rus.LoadByPrimaryKey(log.ReceivingUnitID);
                    //FacilityName.Text = rus.Name;

                    HeaderSection.Text = rus.Name;

                    var activity = new Activity();
                    activity.LoadByPrimaryKey(log.StoreID);
                    lblActivity.Text = activity.Name;
                    lblSubAccount.Text = activity.SubAccountName;
                    lblMode.Text = activity.ModeName;
                    lblAccount.Text = activity.AccountName;

                    lblRegion.Text = rus.RegionName;
                    lblWoreda.Text = rus.WoredaName;
                    lblZone.Text = rus.ZoneName;
                    lblInstType.Text = rus.InstitutionTypeName;

                    var ownership = new OwnershipType();
                    ownership.LoadByPrimaryKey(rus.Ownership);
                    lblOwnership.Text = ownership.Name;

                    lblVoidConDate.Text = (dr["approvalDate"]) != DBNull.Value ? Convert.ToDateTime(dr["approvalDate"]).ToShortDateString(): "-";
                    lblIssueType.Text = (string)dr["OrderType"];
                    User user = new User();

                    if (dr["approvedBy"] != DBNull.Value)
                    {
                        user.LoadByPrimaryKey(Convert.ToInt32(dr["approvedBy"]));
                        lblConfirmedBy.Text = user.FullName;
                    }
                    else
                    {
                        lblConfirmedBy.Text = "-";
                    }

                    var doc = new DocumentType();
                    doc.LoadByPrimaryKey(log.DocumentTypeID);
                    lblDocType.Text = doc.Name;

                    lblPrintedDate.Text = log.PrintedDate.ToShortDateString();

                    var pt = new PaymentType();

                    if (!rus.IsColumnNull("PaymentTypeID"))
                    {
                        pt.LoadByPrimaryKey(rus.PaymentTypeID);
                        lblPaymentType.Text = pt.Name;
                    }

                    else
                    {
                        lblPaymentType.Text = "-";
                    }

                    // Show user name

                    user.LoadByPrimaryKey(log.UserID);
                    lblPrintedBy.Text = (user.FullName == "") ? user.UserName : user.FullName;

                    // show contact person
                    PickList pl = new PickList();
                    pl.LoadByPrimaryKey(log.PickListID);
                    Order order = new Order();
                    order.LoadByPrimaryKey(pl.OrderID);

                    var os = new OrderStatus();
                    os.LoadByPrimaryKey(order.OrderStatusID);
                    lblIssueStatus.Text = os.OrderStatus;

                    if (!order.IsColumnNull("ContactPerson"))
                    {
                        lblRecivedBy.Text = order.ContactPerson;
                    }
                    else
                    {
                        lblRecivedBy.Text = @"-";
                    }

                    lblReceivedDate.Text = order.EurDate.ToShortDateString();

                }

                dtDate.Value = log.PrintedDate;
                //PrintedDate.Text = dtDate.Text;
                lblPrintedDate.Text = dtDate.Text;

                gridTransactions.DataSource = iss.GetIssueBySTV(_stvLogIdChosen.Value);

                layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Never;
                if (BLL.Settings.ShowMissingSTVsOnIssueLog)
                {
                    DataView view = iss.GetPossibleUnconfirmedIssues(_stvLogIdChosen.Value);
                    if (view.Count > 0)
                    {
                        gridUnconfirmed.DataSource = view;
                        layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Always;
                    }
                    else
                    {
                        layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Never;
                    }
                }

            }
        }
        /// <summary>
        /// Handles the FocusedRowChanged event of the gridViewReferences control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs" /> instance containing the event data.</param>
        private void gridViewReferences_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e != null && e.PrevFocusedRowHandle < -1)
            {
                return;
            }

            dtDate.Value = DateTimeHelper.ServerDateTime;
            _reprintId   = null;
            DataRow dr = gridViewReferences.GetFocusedDataRow();

            if (dr == null)
            {
                return;
            }

            string[] referenceNo = new string[2];
            referenceNo[0] = dr["RefNo"].ToString();

            if (Convert.ToBoolean(dr["isConvertedDN"]))
            {
                _isConvertedDn  = true;
                _stvLogIdChosen = (int?)dr["IsReprintOf"];
            }
            else if (dr != null && dr["ID"] != DBNull.Value)
            {
                _isConvertedDn  = false;
                _stvLogIdChosen = (int?)dr["ID"];
            }

            UpdateReprintedNumbers(dr);

            // Enable and disable STV reprint
            // STV SHouldn't be reprinted off a reprint.
            if (dr["IsReprintOf"] != DBNull.Value && !Convert.ToBoolean(dr["isConvertedDN"]))
            {
                btnExport.Enabled = btnReprint.Enabled = false;
                var permission = (BLL.Settings.UseNewUserManagement) ? this.HasPermission("Print") : true;
                btnPrint.Enabled = permission;
                _reprintId       = _stvLogIdChosen;
                _stvLogIdChosen  = Convert.ToInt32(dr["IsReprintOf"]);
            }
            else if (dr["IsDeliveryNote"] != DBNull.Value && Convert.ToBoolean(dr["IsDeliveryNote"]))
            {
                btnExport.Enabled  = false;
                btnReprint.Enabled = (BLL.Settings.UseNewUserManagement) ? this.HasPermission("Re-Print") : true;
                btnPrint.Enabled   = false;
            }
            else
            {
                btnPrint.Enabled   = this.HasPermission("Print");
                btnReprint.Enabled = this.HasPermission("Re-Print");
                btnExport.Enabled  = this.HasPermission("Export");
            }

            if (_stvLogIdChosen != null)
            {
                Issue log = new Issue();
                log.LoadByPrimaryKey(_stvLogIdChosen.Value);


                Institution rus = new Institution();
                IssueDoc    iss = new IssueDoc();
                if (!log.IsColumnNull("ReceivingUnitID"))
                {
                    rus.LoadByPrimaryKey(log.ReceivingUnitID);
                    //FacilityName.Text = rus.Name;

                    HeaderSection.Text = rus.Name;


                    var activity = new Activity();
                    activity.LoadByPrimaryKey(log.StoreID);
                    lblActivity.Text   = activity.Name;
                    lblSubAccount.Text = activity.SubAccountName;
                    lblMode.Text       = activity.ModeName;
                    lblAccount.Text    = activity.AccountName;

                    lblRegion.Text   = rus.RegionName;
                    lblWoreda.Text   = rus.WoredaName;
                    lblZone.Text     = rus.ZoneName;
                    lblInstType.Text = rus.InstitutionTypeName;

                    var ownership = new OwnershipType();
                    ownership.LoadByPrimaryKey(rus.Ownership);
                    lblOwnership.Text = ownership.Name;

                    lblVoidConDate.Text = (dr["approvalDate"]) != DBNull.Value ? Convert.ToDateTime(dr["approvalDate"]).ToShortDateString(): "-";
                    lblIssueType.Text   = (string)dr["OrderType"];
                    User user = new User();

                    if (dr["approvedBy"] != DBNull.Value)
                    {
                        user.LoadByPrimaryKey(Convert.ToInt32(dr["approvedBy"]));
                        lblConfirmedBy.Text = user.FullName;
                    }
                    else
                    {
                        lblConfirmedBy.Text = "-";
                    }

                    var doc = new DocumentType();
                    doc.LoadByPrimaryKey(log.DocumentTypeID);
                    lblDocType.Text = doc.Name;


                    lblPrintedDate.Text = log.PrintedDate.ToShortDateString();



                    var pt = new PaymentType();

                    if (!rus.IsColumnNull("PaymentTypeID"))
                    {
                        pt.LoadByPrimaryKey(rus.PaymentTypeID);
                        lblPaymentType.Text = pt.Name;
                    }

                    else
                    {
                        lblPaymentType.Text = "-";
                    }


                    // Show user name

                    user.LoadByPrimaryKey(log.UserID);
                    lblPrintedBy.Text = (user.FullName == "") ? user.UserName : user.FullName;

                    // show contact person
                    PickList pl = new PickList();
                    pl.LoadByPrimaryKey(log.PickListID);
                    Order order = new Order();
                    order.LoadByPrimaryKey(pl.OrderID);

                    var os = new OrderStatus();
                    os.LoadByPrimaryKey(order.OrderStatusID);
                    lblIssueStatus.Text = os.OrderStatus;


                    if (!order.IsColumnNull("ContactPerson"))
                    {
                        lblRecivedBy.Text = order.ContactPerson;
                    }
                    else
                    {
                        lblRecivedBy.Text = @"-";
                    }

                    lblReceivedDate.Text = order.EurDate.ToShortDateString();
                }

                dtDate.Value = log.PrintedDate;
                //PrintedDate.Text = dtDate.Text;
                lblPrintedDate.Text = dtDate.Text;

                gridTransactions.DataSource = iss.GetIssueBySTV(_stvLogIdChosen.Value);

                layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Never;
                if (BLL.Settings.ShowMissingSTVsOnIssueLog)
                {
                    DataView view = iss.GetPossibleUnconfirmedIssues(_stvLogIdChosen.Value);
                    if (view.Count > 0)
                    {
                        gridUnconfirmed.DataSource       = view;
                        layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Always;
                    }
                    else
                    {
                        layoutUnconfirmedSTVs.Visibility = LayoutVisibility.Never;
                    }
                }
            }
        }
        public static XtraReport CreateInvoice(int stvLogID)
        {
            BLL.Issue       stvLog = new Issue();
            BLL.PickList    pl     = new BLL.PickList();
            BLL.Order       order  = new Order();
            BLL.Institution rus    = new Institution();

            stvLog.LoadByPrimaryKey(stvLogID);
            if (stvLog.IsColumnNull("IsDeliveryNote"))
            {
                stvLog.IsDeliveryNote = false;
            }

            //this makes the assumption that the Insurance is not calculated
            if (stvLog.IsColumnNull("HasInsurance"))
            {
                stvLog.HasInsurance = false;
            }
            if (stvLog.IsColumnNull("IsVoided"))
            {
                stvLog.IsVoided = false;
            }


            pl.LoadByPrimaryKey(stvLog.PickListID);
            order.LoadByPrimaryKey(pl.OrderID);
            if (!order.IsColumnNull("RequestedBy"))
            {
                rus.LoadByPrimaryKey(order.RequestedBy);
            }


            var mode = new Mode();

            mode.LoadByPrimaryKey(order.FromStore);

            DataView dv = pl.GetPickedOrderDetailForOrder(stvLogID, stvLog.IsVoided);

            if (dv.Count == 0 && !stvLog.IsColumnNull("IsRePrintOf"))
            {
                dv = pl.GetPickedOrderDetailForOrder(stvLog.IsReprintOf, stvLog.IsVoided);
            }

            XtraReport report = null;

            if (order.PaymentTypeID == PaymentType.Constants.CASH)
            {
                report = CreateCashInvoice(order, dv.Table, rus, pl, stvLog.IsDeliveryNote, stvLog.HasInsurance,
                                           mode.TypeName, false, stvLogID);
            }
            if (order.PaymentTypeID == PaymentType.Constants.CREDIT)
            {
                report = CreateCreditInvoice(dv.Table, order, pl, rus, stvLog.IsDeliveryNote, stvLog.HasInsurance, mode.TypeName, false, stvLogID);
            }

            if (order.PaymentTypeID == PaymentType.Constants.STV)
            {
                //TODO: Fix this sent to.
                string sentTo = "";
                if (rus.RowCount > 0)
                {
                    sentTo = rus.Name;
                }

                if (!stvLog.IsDeliveryNote)
                {
                    report = CreateSTVonHeadedPaper(order, dv.Table, sentTo, stvLog.PickListID, stvLog.ID, false, false,
                                                    stvLog.HasInsurance, null);
                }
                else
                {
                    report = CreateDeliveryNote(order, dv.Table, sentTo, stvLog.PickListID, stvLog.ID, false, false,
                                                stvLog.HasInsurance, null);
                }
            }

            return(report);
        }
        private static void HandleReceiveDocDeleting(int receiveDocID, int userID, ReceiveDoc rd)
        {
            //Check if there is a Related Picklists
            var pld = new PickListDetail();
            pld.LoadByReceiveDocID(receiveDocID);
            pld.Rewind();
            if(pld.RowCount > 0)
            {
                var pl = new PickList();
                pl.LoadByPrimaryKey(pld.PickListID);

                var order = new Order();
                order.LoadByPrimaryKey(pl.OrderID);

                string printedIDs = "";
                var stvs = new BLL.Issue();
                stvs.Where.PickListID.Value = pl.ID;
                stvs.Query.Load();
                stvs.Rewind();
                while (!stvs.EOF)
                {
                    printedIDs += stvs.IDPrinted.ToString(CultureInfo.InvariantCulture) + " ,";
                    stvs.MoveNext();
                }
                printedIDs = printedIDs.Remove(printedIDs.Length - 1, 1);
                throw new Exception(
                    string.Format("Please cancel/void the following Stvs: Ref No = {0} With PrintedIDs : {1}",
                                  order.RefNo,printedIDs));
            }

            // Add new record on ReceiveDocDeleted
            var recDel = ReceiveDocDeleted.AddNewLog(rd, userID);

            // Delete related ReceivePallet
            var receivePallet = new BLL.ReceivePallet();
            receivePallet.LoadByReceiveDocID(receiveDocID);
            receivePallet.Rewind();
            while(!receivePallet.EOF)
            {
                receivePallet.MarkAsDeleted();
                receivePallet.MoveNext();
            }

            // Delete related ReceivePriceConfirmation
            var receivePriceConfirmation = new ReceivePriceConfirmation();
            receivePriceConfirmation.LoadByReceiveDocID(rd.ID);
            receivePriceConfirmation.MarkAsDeleted();

            // Delete related ReceiveDocShortage
            var rdShr = new ReceiveDocShortage();
            rdShr.Where.ReceiveDocID.Value = rd.ID;
            rdShr.Query.Load();
            rdShr.Rewind();
            while(!rdShr.EOF)
            {
                rdShr.MarkAsDeleted();
                rdShr.MoveNext();
            }

            // Delete related ReceiveDocConfirmation
            var rdConf = new ReceiveDocConfirmation();
            rdConf.Where.ReceiveDocID.Value = rd.ID;
            rdConf.Query.Load();
            rdConf.Rewind();
            while(!rdConf.EOF)
            {
                rdConf.MarkAsDeleted();
                rdConf.MoveNext();
            }

            rd.MarkAsDeleted();

            var transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            transaction.BeginTransaction();
            try
            {
                receivePallet.Save();
                receivePriceConfirmation.Save();
                rdShr.Save();
                rdConf.Save();
                recDel.Save();
                rd.Save();
                transaction.CommitTransaction();
            }
            catch (Exception exception)
            {
                transaction.RollbackTransaction();
                throw;
            }
        }