Example #1
0
        internal virtual string GetInvoiceSumm(DateTime printdate1, DateTime printdate2)
        {
            string text       = "";
            bool   isSamedate = printdate1 == printdate2;

            PrintSummHeader(printdate1, printdate2, ref text, isSamedate);
            var invs = DataHelper.GetInvoices(printdate1, printdate2);

            var grp = from inv in invs
                      group inv by inv.invdate
                      into g select new { key = g.Key, results = g };

            double ttlcash   = 0;
            double ttlInv    = 0;
            double ttltax    = 0;
            double ttlamt    = 0;
            double subttltax = 0;
            double subttlamt = 0;
            bool   multiType = false;
            string line      = "";
            int    cont      = 0;

            foreach (var g in grp)               //group by date
            {
                var list   = g.results.OrderBy(x => x.invno);
                var typgrp = from ty in list
                             group ty by ty.trxtype into tg
                             select new { key = tg.Key, results = tg };

                if (!isSamedate)
                {
                    text = text + g.key.ToString("dd-MM-yyyy") + "\n";
                    text = text + "---------- \n";
                }
                multiType = (typgrp.Count() > 1);
                foreach (var tygrp in typgrp)                    //group by trxtype
                {
                    text = text + "[ " + tygrp.key.ToUpper() + " ]\n";
                    var list2 = tygrp.results.OrderBy(x => x.invno);
                    subttltax = 0;
                    subttlamt = 0;
                    cont      = 0;
                    foreach (Invoice inv in list2)
                    {
                        cont      += 1;
                        ttltax    += inv.taxamt;
                        ttlamt    += inv.amount;
                        subttltax += inv.taxamt;
                        subttlamt += inv.amount;
                        if (tygrp.key.ToUpper() == "CASH")
                        {
                            ttlcash = ttlcash + inv.amount + inv.taxamt;
                        }
                        else
                        {
                            ttlInv = ttlInv + inv.amount + inv.taxamt;
                        }
                        line = (cont.ToString() + ".").PadRight(4, ' ') +
                               inv.invno.PadRight(16, ' ') +
                               //inv.trxtype.PadRight (8, ' ') +
                               inv.taxamt.ToString("n2").PadLeft(10, ' ') +
                               inv.amount.ToString("n2").PadLeft(12, ' ') + "\n";
                        text = text + line;
                    }
                    //if (multiType) {
                    if (typgrp.Count() > 1)
                    {
                        text = text + PrintSubTotal(subttltax, subttlamt);
                    }
                    //	}
                    text = text + "\n";
                }
            }

            double ttlCNTax    = 0;
            double ttlCNAmt    = 0;
            double ttlCNCODTax = 0;
            double ttlCNCODAmt = 0;
            double ttlCN       = 0;
            double ttlCNCOD    = 0;
            var    cns         = DataHelper.GetCNNote(printdate1, printdate2);

            foreach (CNNote cn in cns)
            {
                if (cn.trxtype == "CASH")
                {
                    ttlCNCODTax = ttlCNCODTax + cn.taxamt;
                    ttlCNCODAmt = ttlCNCODAmt + cn.amount;
                }
                else
                {
                    ttlCNTax = ttlCNTax + cn.taxamt;
                    ttlCNAmt = ttlCNAmt + cn.amount;
                }
            }
            ttlCN    = ttlCNTax + ttlCNAmt;
            ttlCNCOD = ttlCNCODTax + ttlCNCODAmt;

            double ttl         = ttlamt + ttltax;
            double cashCollect = ttlcash - ttlCNCOD;

            PrintSummFooter(ref text, ttlcash, ttlInv, ttltax, ttlamt, ttlCN, ttlCNCOD, ttl, cashCollect);

            return(text);
        }
Example #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            if (!((GlobalvarsApp)this.Application).ISLOGON)
            {
                Finish();
            }
            SetTitle(Resource.String.title_creditnoteedit);
            SetContentView(Resource.Layout.CreateCNote);
            EventManagerFacade.Instance.GetEventManager().AddListener(this);
            pathToDatabase = ((GlobalvarsApp)this.Application).DATABASE_PATH;

            CNNO   = Intent.GetStringExtra("cnno") ?? "AUTO";
            cnInfo = DataHelper.GetCNNote(pathToDatabase, CNNO);

            // Create your application here
            _date   = DateTime.Today;
            spinner = FindViewById <Spinner> (Resource.Id.newinv_custcode);

            Button butSave = FindViewById <Button> (Resource.Id.newinv_bsave);

            butSave.Text = "SAVE";
            Button butCancel  = FindViewById <Button> (Resource.Id.newinv_cancel);
            Button butFind    = FindViewById <Button> (Resource.Id.newinv_bfind);
            Button butFindInv = FindViewById <Button> (Resource.Id.newinv_bfindinv);

            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);
            butSave.Click        += butSaveClick;
            butCancel.Click      += butCancelClick;
            TextView cnno = FindViewById <TextView> (Resource.Id.newinv_no);

            cnno.Enabled = false;
            EditText trxdate = FindViewById <EditText> (Resource.Id.newinv_date);

//			trxdate.Click += delegate(object sender, EventArgs e) {
//				ShowDialog (0);
//			};
            //19-Nov-2015
            //disable the date, for edit mode, date should not be editable
            //cuase running number issue.
            trxdate.Enabled = false;

            butFind.Click += (object sender, EventArgs e) => {
                ShowCustLookUp();
            };

            butFindInv.Click += (object sender, EventArgs e) => {
                ShowInvLookUp();
            };


            apara = DataHelper.GetAdPara(pathToDatabase);
            //SqliteConnection.CreateFile(pathToDatabase);
            using (var db = new SQLite.SQLiteConnection(pathToDatabase))
            {
                items = db.Table <Trader> ().ToList <Trader> ();
            }

            List <string> icodes = new List <string> ();

            foreach (Trader item in items)
            {
                icodes.Add(item.CustCode + " | " + item.CustName.Trim());
            }
            dataAdapter = new ArrayAdapter <String>(this, Resource.Layout.spinner_item, icodes);
            // Drop down layout style - list view with radio button
            //dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            dataAdapter.SetDropDownViewResource(Resource.Layout.SimpleSpinnerDropDownItemEx);
            // attaching data adapter to spinner
            spinner.Adapter = dataAdapter;
            LoadData();
        }
Example #3
0
        public static ModelSumm GetInvoiceSummModel(string pathToDatabase, string userID, DateTime printDate1, DateTime printDate2)
        {
            ModelSumm model = new ModelSumm();

            model.DailyTrx  = new List <ModelSummDate> ();
            model.GrpPrices = new List <ModelGrpPrice> ();

            var           itemCodes = DataHelper.GetItems();
            var           invs      = DataHelper.GetInvoices(printDate1, printDate2);
            var           cns       = DataHelper.GetCNNote(printDate1, printDate2);
            List <string> invnos    = new List <string> ();

            foreach (var itm in invs)
            {
                invnos.Add(itm.invno);
            }

            List <string> cnnosTmp = new List <string> ();

            foreach (var cnitm in cns)
            {
                cnnosTmp.Add(cnitm.cnno);
            }

            using (var db = new SQLite.SQLiteConnection(pathToDatabase, true)) {
                var itemlist = from p in db.Table <InvoiceDtls> ()
                               where invnos.Contains(p.invno)
                               select p;

                var cnitemlist = from p in db.Table <CNNoteDtls> ()
                                 where cnnosTmp.Contains(p.cnno)
                                 select p;

                model.PrintDate   = DateTime.Now;
                model.UserID      = "MOK";
                model.Company     = db.Table <CompanyInfo> ().Take(1).FirstOrDefault();
                model.TotalCash   = GetSumTotal(invs, "CASH", itemlist.ToList(), itemCodes, model);
                model.TotalInv    = GetSumTotal(invs, "INVOICE", itemlist.ToList(), itemCodes, model);
                model.TotalCNInv  = GetCNSumTotal(cns, "INVOICE", cnitemlist.ToList(), itemCodes, model);
                model.TotalCNCash = GetCNSumTotal(cns, "CASH", cnitemlist.ToList(), itemCodes, model);

                var grpitm = from code in itemlist
                             group code by code.icode
                             into g
                             select new { key = g.Key, idesc = g.Max(x => x.description), results = g };


                foreach (var grpicode in grpitm)
                {
                    var grpprice = from icode in grpicode.results
                                   group icode by icode.price into g
                                   select new { key     = g.Key,
                                                tax     = g.Sum(x => x.tax),
                                                amount  = g.Sum(x => x.netamount),
                                                qty     = g.Sum(x => x.qty),
                                                results = g };

                    ModelGrpPrice mprice = new ModelGrpPrice();
                    mprice.ICode     = grpicode.key;
                    mprice.IDesc     = grpicode.idesc;
                    mprice.PriceList = new List <GrpPriceList>();

                    foreach (var itm in grpprice)
                    {
                        GrpPriceList gprice = new GrpPriceList();
                        gprice.Amount = itm.amount;
                        gprice.Price  = itm.key;
                        gprice.Qty    = itm.qty;
                        gprice.TaxAmt = itm.tax;
                        mprice.PriceList.Add(gprice);
                    }
                    model.GrpPrices.Add(mprice);
                }

//				var grp = from inv in invs
//					group inv by inv.invdate into g
//					select new { key = g.Key, results = g };


                ModelSummDate summ = new ModelSummDate();
                summ.Date     = printDate1;
                summ.CashList = new List <Invoice> ();
                summ.InvList  = new List <Invoice> ();

                var typgrp = from ty in invs
                             group ty by ty.trxtype into tg
                             select new { key = tg.Key, results = tg };
                foreach (var g1 in typgrp)
                {
                    if (g1.key == "CASH")
                    {
                        summ.CashList = g1.results.OrderBy(x => x.invno).ToList();
                    }
                    else
                    {
                        summ.InvList = g1.results.OrderBy(x => x.invno).ToList();
                    }
                }

                var typgrp2 = from ty in cns
                              group ty by ty.trxtype into tg
                              select new { key = tg.Key, results = tg };
                foreach (var g1 in typgrp2)
                {
                    if (g1.key == "CASH")
                    {
                        summ.CashCNList = g1.results.OrderBy(x => x.cnno).ToList();
                    }
                    else
                    {
                        summ.InvCNList = g1.results.OrderBy(x => x.cnno).ToList();
                    }
                }

                model.DailyTrx.Add(summ);
                model.TtlTaxSumm = new List <TaxSumm> ();
                model.TtlTaxSumm = GeTotalTaxSumm(model.TtlTaxSumm, model.InvTaxSumm);
                model.TtlTaxSumm = GeTotalTaxSumm(model.TtlTaxSumm, model.CSTaxSumm);
                model.TtlTaxSumm = GeTotalTaxSumm(model.TtlTaxSumm, model.CNInvTaxSumm);
                model.TtlTaxSumm = GeTotalTaxSumm(model.TtlTaxSumm, model.CNCSTaxSumm);
            }
            return(model);
        }