Пример #1
0
 private void ExecuteSave(object obj)
 {
     try
     {
         if (!ParkingList.Any(x => x.Close))
         {
             MessageBox.Show("No entrance is checked for closing.", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (ParkingList.Any(x => x.Close && string.IsNullOrEmpty(x.Remarks)))
         {
             MessageBox.Show("Remarks must be given for closing the entrance", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             conn.Open();
             using (SqlTransaction tran = conn.BeginTransaction())
             {
                 foreach (var p in ParkingList.Where(x => x.Close))
                 {
                     ParkingOut pout = new ParkingOut()
                     {
                         PID        = p.PID,
                         FYID       = p.FYID,
                         OutDate    = p.InDate,
                         OutMiti    = p.InMiti,
                         OutTime    = p.InTime,
                         SESSION_ID = GlobalClass.Session,
                         UID        = GlobalClass.User.UID,
                         Remarks    = p.Remarks,
                         Interval   = string.Empty,
                         Rate_ID    = 1
                     };
                     pout.Save(tran);
                 }
                 tran.Commit();
                 MessageBox.Show("Success", MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 ParkingList.Clear();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.GetBaseException().Message, MessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        public FunctionResponse ExecuteSave(BarCodeTransfer obj)
        {
            int            Session   = obj.Session;
            List <Voucher> Vouchers  = obj.Vouchers;
            string         barcode   = obj.barcode;
            MemberDiscount mDiscount = obj.mDiscount;
            ParkingOut     POUT      = obj.POUT;

            GlobalClass.GetUser(POUT.UID);

            string  strSQL;
            decimal Taxable, VAT, Amount, Discount = 0, NonTaxable, Rate, Quantity;
            string  BillNo = string.Empty;

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionDbInfo.ConnectionString))
                {
                    conn.Open();
                    using (SqlTransaction tran = conn.BeginTransaction())
                    {
                        POUT.SESSION_ID = Session;
                        POUT.FYID       = GlobalClass.FYID;
                        POUT.Save(tran);
                        if (POUT.CashAmount > 0)
                        {
                            BillNo   = InvoicePrefix + GlobalClass.GetInvoiceNo(InvoicePrefix, tran);
                            Quantity = POUT.ChargedHours;
                            if (Vouchers.Count > 0)
                            {
                                Discount = Vouchers.Sum(x => x.Value);
                            }
                            else if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId))
                            {
                                Discount = mDiscount.DiscountAmount;
                            }
                            else if (POUT.CashAmount < POUT.ChargedAmount)
                            {
                                Discount = POUT.ChargedAmount - POUT.CashAmount;
                            }
                            Amount     = POUT.ChargedAmount / (1 + (GlobalClass.VAT / 100));
                            Discount   = Discount / (1 + (GlobalClass.VAT / 100));
                            Rate       = Amount / Quantity;
                            NonTaxable = 0;
                            Taxable    = Amount - (NonTaxable + Discount);
                            VAT        = Taxable * GlobalClass.VAT / 100;

                            TParkingSales PSales = new TParkingSales
                            {
                                BillNo      = BillNo,
                                TDate       = POUT.OutDate,
                                TMiti       = POUT.OutMiti,
                                TTime       = POUT.OutTime,
                                BillTo      = POUT.BILLTO,
                                BILLTOADD   = POUT.BILLTOADD,
                                BILLTOPAN   = POUT.BILLTOPAN,
                                Amount      = Amount,
                                Discount    = Discount,
                                NonTaxable  = NonTaxable,
                                Taxable     = Taxable,
                                VAT         = VAT,
                                GrossAmount = POUT.CashAmount,
                                PID         = POUT.PID,
                                UID         = POUT.UID,
                                SESSION_ID  = POUT.SESSION_ID,
                                FYID        = GlobalClass.FYID,
                                TaxInvoice  = TaxInvoice
                            };
                            PSales.Save(tran);
                            TParkingSalesDetails PSalesDetails = new TParkingSalesDetails
                            {
                                BillNo      = BillNo,
                                PType       = 'P',
                                Description = "Parking Charge",
                                FYID        = GlobalClass.FYID,
                                Quantity    = Quantity,
                                Rate        = Rate,
                                Amount      = Amount,
                                Discount    = Discount,
                                NonTaxable  = NonTaxable,
                                Taxable     = Taxable,
                                VAT         = VAT,
                                NetAmount   = POUT.CashAmount,
                            };
                            PSalesDetails.Save(tran);

                            conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = @VNAME AND FYID = @FYID", new { VNAME = InvoicePrefix, FYID = GlobalClass.FYID }, transaction: tran);


                            GlobalClass.SetUserActivityLog(tran, "Exit", "New", VCRHNO: BillNo, WorkDetail: "Bill No : " + BillNo);
                            //SyncFunctions.LogSyncStatus(tran, BillNo, GlobalClass.FYNAME);
                        }
                        if (Vouchers.Count > 0)
                        {
                            strSQL = "INSERT INTO VoucherDiscountDetail (BillNo, FYID, VoucherNo, DiscountAmount, UID) VALUES (@BillNo, @FYID, @VoucherNo, @DiscountAmount, @UID)";
                            foreach (Voucher v in Vouchers)
                            {
                                conn.Execute(strSQL, new
                                {
                                    BillNo         = string.IsNullOrEmpty(BillNo) ? "CS1" : BillNo,
                                    FYID           = GlobalClass.FYID,
                                    VoucherNo      = v.VoucherNo,
                                    DiscountAmount = v.Value,
                                    UID            = POUT.UID
                                }, transaction: tran);
                                conn.Execute("UPDATE ParkingVouchers SET ScannedTime = GETDATE() WHERE VoucherNo = @VoucherNo", v, tran);
                            }
                        }
                        else if (mDiscount != null && !string.IsNullOrEmpty(mDiscount.MemberId))
                        {
                            mDiscount.BillNo = string.IsNullOrEmpty(BillNo) ? "MS1" : BillNo;
                            mDiscount.Save(tran);
                        }
                        tran.Commit();
                        //if (!string.IsNullOrEmpty(SyncFunctions.username) && POUT.CashAmount > 0)
                        //{
                        //    SyncFunctions.SyncSalesData(SyncFunctions.getBillObject(BillNo), 1);
                        //}
                    }
                    //if (!string.IsNullOrEmpty(BillNo))
                    //{
                    //    RawPrinterHelper.SendStringToPrinter(GlobalClass.PrinterName, ((char)27).ToString() + ((char)112).ToString() + ((char)0).ToString() + ((char)64).ToString() + ((char)240).ToString(), "Receipt");   //Open Cash Drawer
                    //    PrintBill(BillNo.ToString(), conn, (TaxInvoice) ? "TAX INVOICE" : "ABBREVIATED TAX INVOCE");
                    //    if (TaxInvoice)
                    //    {
                    //        PrintBill(BillNo.ToString(), conn, "INVOICE");
                    //    }
                    //}

                    return(new FunctionResponse()
                    {
                        status = "ok", Message = "Saved Successfully"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new FunctionResponse()
                {
                    status = "error", Message = ex.Message
                });
            }
        }