Exemplo n.º 1
0
        public ActionResult Calculate(int contract, DateTime from, DateTime to)
        {
            var ocont = context.Contracts.Where(c => c.id == contract).SingleOrDefault();

            var pu = new PriceUpdaterLib.PriceUpdater(context);

            decimal deuda = 0;

            deuda = pu.CreditBalanceFor(ocont.lritid, from, to);

            return(Content(((decimal)deuda).ToString(CultureInfo.InvariantCulture)));
        }
Exemplo n.º 2
0
        public ActionResult Create(Invoice invoice)
        {
            if (!ModelState.IsValid)
            {
                MakeCombos();
                FlashError("Error intentando guardar, verifique los campos");
                return(View("New", invoice));
            }

            try
            {
                if (invoice.id == 0)
                {
                    FlashOK("La factura fue creada correctamente");

                    context.Invoices.InsertOnSubmit(invoice);
                    context.SubmitChanges();

                    //Update contracts last facturado
                    DateTime?maxDate = context.Invoices.Where(i => i.contract_id == invoice.contract_id && i.emitidarecibida == invoice.emitidarecibida).Max(i => (DateTime?)i.dateTo);
                    if (maxDate != null)
                    {
                        //Save last date
                        var contract = context.Contracts.Where(c => c.id == invoice.contract_id).SingleOrDefault();
                        if (invoice.emitidarecibida == 0)
                        {
                            contract.lastInvoice = (DateTime)maxDate;
                        }
                        else
                        {
                            contract.lastInvoiceRecv = (DateTime)maxDate;
                        }

                        context.SubmitChanges();

                        //Recalculate contract account
                        var pu = new PriceUpdaterLib.PriceUpdater(Config.ConnectionString);
                        pu.UpdateContracts((DateTime)maxDate, new string[] { invoice.Contract.lritid });
                    }
                }
                else
                {
                    FlashOK("La factura se actualizo con exito");

                    var updatedInvoice = context.Invoices.Where(c => c.id == invoice.id).SingleOrDefault();
                    updatedInvoice.SimpleCopyFrom(invoice, new string[] { "state", "contract_id", "invoiceNumber", "isueDate", "dateFrom", "dateTo", "amount", "currency", "transfercost", "interests", "bankreference", "notes" });

                    //Process file
                    if (Request.Files.Count != 0)
                    {
                        var file = Request.Files[0];
                        if (file.ContentLength > 0)
                        {
                            byte[] tmp = new byte[file.ContentLength];
                            file.InputStream.Read(tmp, 0, file.ContentLength);
                            if (updatedInvoice.invoiceFile_id == null)
                            {
                                updatedInvoice.InvoiceFile = new InvoiceFile();
                            }

                            updatedInvoice.InvoiceFile.fileContent = tmp;
                            updatedInvoice.InvoiceFile.fileName    = Path.GetFileName(file.FileName);
                            updatedInvoice.InvoiceFile.fileType    = file.ContentType;
                        }
                    }


                    context.SubmitChanges();
                }

                return(Edit(invoice.id));
            }
            catch (Exception ex)
            {
                FlashError(string.Format("Error inesperado: {0}", ex.Message));
            }

            MakeCombos();
            return(View("New", invoice));
        }