Ejemplo n.º 1
0
        private static void Post(PostTransaction pt)
        {
            try
            {
                //throw new ApplicationException("This is test Error");
                IncludePrecriptionProperties(pt.TransactionData);

                SalesReceipt s = new SalesReceipt();
                s.TxnDate            = pt.TransactionData.Time;
                s.TxnState           = "1";
                s.Workstation        = "02";
                s.StoreNumber        = "1";
                s.SalesReceiptNumber = "123";
                s.DiscountPercent    = "0";

                Patient dbPatient = null;

                if (pt.TransactionData == null || string.IsNullOrEmpty(pt.TransactionData.TransactionNumber))
                {
                    //MessageBox.Show("Invalid Transaction Please Try again");
                    //TransactionData.Status = "Invalid Transaction Please Try again";
                    //rms.SaveChanges();
                    //return;
                }

                //TransPreZeroConverter tz = new TransPreZeroConverter();
                var patientRewards = new List <PatientAvailableReward>();

                if (pt.TransactionData is Prescription)
                {
                    Prescription p       = pt.TransactionData as Prescription;
                    string       doctor  = "";
                    string       patient = "";
                    if (p.Doctor != null)
                    {
                        doctor = p.Doctor.DisplayName;
                        //s.DiscountPercent = p.Doctor.Discount == null ? "" : p.Doctor.Discount.ToString();
                    }
                    if (p.Patient != null)
                    {
                        patient = p.Patient.ContactInfo;
                        //s.DiscountPercent = p.Patient.Discount == null ? "" : p.Patient.Discount.ToString();
                        patientRewards.AddRange(p.Patient.AvailableRewards.ToList());
                    }
                    s.Comments = String.Format("{0} \n RX#:{1} \n Doctor:{2}", patient,
                                               p.TransactionNumber, doctor);


                    var qbCustomer = QBPOS.GetOrAddCustomerQuery(p.Patient, Settings.Default.QBCompanyFile);
                    if (!string.IsNullOrEmpty(p.Patient?.PhoneNumber) && p.Patient?.IDCardInfo.FirstOrDefault() != null)
                    {
                        dbPatient = UpdateCustomer(qbCustomer);
                        if (p.Patient?.QBCustomer?.CustomerListID != null)
                        {
                            s.CustomerListId = p.Patient.QBCustomer.CustomerListID;
                        }
                    }
                }
                else
                {
                    QuickPrescription p = pt.TransactionData as QuickPrescription;
                    s.Comments = $"{p.Patient.ContactInfo} \n RX#: {pt.TransactionData.TransactionNumber}";

                    if (p.Patient != null)
                    {
                        if (!string.IsNullOrEmpty(p.Patient.PhoneNumber) && p.Patient?.IDCardInfo.FirstOrDefault() != null)
                        {
                            var qbCustomer = QBPOS.GetOrAddCustomerQuery(p.Patient, Settings.Default.QBCompanyFile);
                            dbPatient = UpdateCustomer(qbCustomer);
                            if (p.Patient?.QBCustomer?.CustomerListID != null)
                            {
                                s.CustomerListId = qbCustomer.ListID;
                            }
                        }

                        patientRewards.AddRange(p.Patient.AvailableRewards.ToList());
                    }
                }



                if (pt.TransactionData != null)
                {
                    s.TrackingNumber = pt.TransactionData.TransactionNumber;
                }
                s.Associate        = "Dispensary";
                s.SalesReceiptType = "0";



                foreach (var item in pt.PostEntries)
                {
                    var qbitm = QBPOS.ValidateInventoryItemQuery(item.QBListId, Settings.Default.QBCompanyFile);
                    if (!qbitm.Any())
                    {
                        //SetQBInactive(item.QBListId);
                        //pt.TransactionData.Status = "Can't Post Because Item Not In QuickBooks";
                        //UpdateTransactionDataFromSalesRet(pt, new QBResult() { Comments = "Item Not In QuickBooks" });
                        //return;
                        continue;
                    }
                    else
                    {
                        UpdateInventoryItem(qbitm);
                    }

                    s.SalesReceiptDetails.Add(new SalesReceiptDetail
                    {
                        ItemListID = item.QBListId,
                        //   ItemNumber = item.ItemNumber,
                        QtySold = item.Quantity,
                        //Discount = dbPatient?.PatientMemberships.FirstOrDefault()?.MembershipType?.Discount ?? dbPatient?.Discount ?? 0.0
                    }); //340
                }


                foreach (var reward in patientRewards.Where(x => x.Status != null && x.Status.Contains("Issued") && x.StoreName == Store.StoreCode).ToList())
                {
                    var itm = new RMSModel().Item.FirstOrDefault(x => x.ItemNumber == reward.ItemNumber.ToString());
                    if (itm != null)
                    {
                        var qbitm = QBPOS.ValidateInventoryItemQuery(itm.QBItemListID, Settings.Default.QBCompanyFile).FirstOrDefault();
                        if (qbitm != null)
                        {
                            s.SalesReceiptDetails.Add(new SalesReceiptDetail
                            {
                                ItemListID = qbitm.ListID,
                                //   ItemNumber = item.ItemNumber,
                                QtySold = 1,
                                //Discount = reward.Value
                            }); //340
                        }
                    }
                    else
                    {
                        //s.Discount = reward.Value.ToString();
                    }

                    s.Comments += $"\r\nReward:{reward.Name}";
                }



                var result = QBPOS.AddSalesReceipt(s, Settings.Default.QBCompanyFile);

                UpdateTransactionDataFromSalesRet(pt, result);
            }
            catch (Exception ex)
            {
                var msg = CleanErrorMessage(ex.Message);
                Logger.Log(LoggingLevel.Error, "error found for #" + pt.TransactionData.TransactionNumber + ":---:" + msg + ex.StackTrace);
                Singleton.Status = "error found for #" + pt.TransactionData.TransactionNumber;
                UpdateTransactionDataStatus(pt, msg);
                if (msg.Contains("Can't connect to the database"))
                {
                    MessageBox.Show(msg);
                    postingTimer.Enabled = false;
                    throw ex;
                }
            }
        }
Ejemplo n.º 2
0
        private static void Post(PostTransaction pt)
        {
            try
            {
                //throw new ApplicationException("This is test Error");
                IncludePrecriptionProperties(pt.TransactionData);

                SalesReceipt s = new SalesReceipt();
                s.TxnDate            = pt.TransactionData.Time;
                s.TxnState           = "1";
                s.Workstation        = "02";
                s.StoreNumber        = "1";
                s.SalesReceiptNumber = "123";
                s.Discount           = "0";

                if (pt.TransactionData == null || string.IsNullOrEmpty(pt.TransactionData.TransactionNumber))
                {
                    //MessageBox.Show("Invalid Transaction Please Try again");
                    //TransactionData.Status = "Invalid Transaction Please Try again";
                    //rms.SaveChanges();
                    //return;
                }

                //TransPreZeroConverter tz = new TransPreZeroConverter();

                if (pt.TransactionData is Prescription)
                {
                    Prescription p       = pt.TransactionData as Prescription;
                    string       doctor  = "";
                    string       patient = "";
                    if (p.Doctor != null)
                    {
                        doctor     = p.Doctor.DisplayName;
                        s.Discount = p.Doctor.Discount == null ? "" : p.Doctor.Discount.ToString();
                    }
                    if (p.Patient != null)
                    {
                        patient    = p.Patient.ContactInfo;
                        s.Discount = p.Patient.Discount == null ? "" : p.Patient.Discount.ToString();
                    }
                    s.Comments = String.Format("{0} \n RX#:{1} \n Doctor:{2}", patient,
                                               p.TransactionNumber, doctor);
                }
                else
                {
                    s.Comments = "RX#:" + pt.TransactionData.TransactionNumber;
                }


                if (pt.TransactionData != null)
                {
                    s.TrackingNumber = pt.TransactionData.TransactionNumber;
                }
                s.Associate        = "Dispensary";
                s.SalesReceiptType = "0";



                foreach (var item in pt.PostEntries)
                {
                    var qbitm = QBPOS.ValidateInventoryItemQuery(item.QBListId, Settings.Default.QBCompanyFile);
                    if (!qbitm.Any())
                    {
                        //SetQBInactive(item.QBListId);
                        //pt.TransactionData.Status = "Can't Post Because Item Not In QuickBooks";
                        //UpdateTransactionDataFromSalesRet(pt, new QBResult() { Comments = "Item Not In QuickBooks" });
                        //return;
                        continue;
                    }
                    else
                    {
                        UpdateInventoryItem(qbitm);
                    }

                    s.SalesReceiptDetails.Add(new SalesReceiptDetail
                    {
                        ItemListID = item.QBListId,
                        ItemNumber = item.ItemNumber,
                        QtySold    = item.Quantity
                    });     //340
                }



                var result = QBPOS.AddSalesReceipt(s, Settings.Default.QBCompanyFile);
                if (result != null)
                {
                    UpdateTransactionDataFromSalesRet(pt, result);
                }
            }
            catch (Exception ex)
            {
                var msg = CleanErrorMessage(ex.Message);
                Logger.Log(LoggingLevel.Error, "error found for #" + pt.TransactionData.TransactionNumber + ":---:" + msg + ex.StackTrace);
                Singleton.Status = "error found for #" + pt.TransactionData.TransactionNumber;
                UpdateTransactionDataStatus(pt, msg);
                if (msg.Contains("Can't connect to the database"))
                {
                    MessageBox.Show(msg);
                    postingTimer.Enabled = false;
                    throw ex;
                }
            }
        }