public void RecalcTotals() { WebUserControlRentMaterials1.LoadOrderLines(); WebUserControlRentMaterials1.RecalcTotals(); LabelTotalItemsValue.Text = WebUserControlRentMaterials1.TotalRentalItemAmount.ToString(); LabelTotalPriceValue.Text = WebUserControlRentMaterials1.TotalRentPrice.ToString(); TextBoxBail.Text = WebUserControlRentMaterials1.TotalBailPrice.ToString(); }
protected void ButtonPrintAndProcess_Click(object sender, EventArgs e) { bool Success = false; ModelTMSContainer _ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session); // start transaction using (TransactionScope TS = new TransactionScope()) { try { // expand rented items if required WebUserControlRentMaterials1.ExpandOrderLines(); // by default we have no invoice LabelCurrentInvoiceId.Text = ""; // create rentledger entry and link up the rentalitemactivities RentLedger TempRentLedger = new RentLedger(); _ControlObjectContext.AddToRentLedgerSet(TempRentLedger); if (LabelGroupId.Text == "") { LabelGroupId.Text = TempRentLedger.Id.ToString(); } TempRentLedger.Relation = _ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationSet", "Id", Guid.Parse(DropDownListCustomers.SelectedValue))) as Relation; TempRentLedger.Location = _ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", Guid.Parse(DropDownListLocations.SelectedValue))) as Location; TempRentLedger.Description = TextBox_Description.Text; WebUserControlRentMaterials1.AddRentMaterialsToRentLedgerAndRentalItemActivitySet(_ControlObjectContext, TempRentLedger); // create invoice if required and link this up to the rentledger if ((LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked)) { Invoice TempInvoice = new Invoice(); // copy the group code if this is a correction from an old invoice Guid OldGuid = Guid.Parse(LabelCurrentOrderId.Text); if (OldGuid != Guid.Empty) { try { Invoice OldInvoice = _ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.InvoiceSet", "Id", OldGuid)) as Invoice; TempInvoice.GroupCode = OldInvoice.GroupCode; } catch { }; } // reset the invoice LabelCurrentOrderId.Text = Guid.Empty.ToString(); // continue processing TempInvoice.Relation = _ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RelationSet", "Id", Guid.Parse(DropDownListCustomers.SelectedValue))) as Relation; TempInvoice.Location = _ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", Guid.Parse(DropDownListLocations.SelectedValue))) as Location; TempInvoice.Description = TextBox_Description.Text; TempInvoice.InvoiceType = "Sell"; TempInvoice.InvoiceSubType = "Rent"; TempInvoice.BookingDateTime = Common.CurrentClientDateTime(Session); if (LabelRentMode.Text == "Cash") { TempInvoice.Ledger = TempInvoice.Location.CashLedger; } else { TempInvoice.Ledger = TempInvoice.Location.BankLedger; } TempInvoice.GroupCode = new Guid(LabelGroupId.Text); TempInvoice.DiscountPercentage = Convert.ToDouble(TextBoxInvoiceDiscount.Text); if (LabelRentMode.Text != "Cash") { TempInvoice.Ledger = TempInvoice.Location.BankLedger; } TempInvoice.InvoiceNote = TextBoxInvoiceNote.Text; _ControlObjectContext.AddToInvoiceSet(TempInvoice); TempRentLedger.Invoice.Add(TempInvoice); // add the order to the invoice TempRentLedger.AddRentMaterialsToInvoice(_ControlObjectContext, TempInvoice); // add bail to the invoice double Bail = Convert.ToDouble(TextBoxBail.Text); // except if this fails, this should be a valid number if (Bail != 0) { InvoiceLine iline = new InvoiceLine(); iline.Description = "Borg"; iline.OriginalPrice = Bail; iline.AllowDiscount = false; iline.VATPercentage = 0; iline.VATPrice = 0; iline.TotalPrice = Bail; iline.Invoice = TempInvoice; iline.LineNumber = iline.Invoice.InvoiceLine.Count; iline.LedgerBookingCode = iline.Invoice.Location.DefaultBailPriceBookingCode; } // all invoice lines to the same ledger TempInvoice.AllInvoiceLinesToSameLedger(TempInvoice.Ledger); TempInvoice.RecalcTotals(); // process order & invoice if this is a cash invoice if (LabelRentMode.Text == "Cash") { TempInvoice.ProcessInvoice(_ControlObjectContext, TempInvoice.GroupCode, true, Common.CurrentClientDateTime(Session)); } else { TempInvoice.GenerateInvoiceNumber(_ControlObjectContext); } LabelCurrentInvoiceId.Text = TempInvoice.Id.ToString(); } TempRentLedger.CheckRentLedgerBeforeSave(_ControlObjectContext); // and save to persistent storage _ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave); // and save this invoice LabelCurrentOrderId.Text = TempRentLedger.Id.ToString(); // commit the transaciton TS.Complete(); Success = true; } catch (Exception ex) // commit or procedure failed somewhere { // rollback transaction TS.Dispose(); // inform user Common.InformUserOnTransactionFail(ex, Page); } } if (Success) { // when success advance panel CurrentPageNr = CurrentPageNr + 1; EnableCorrectScreenElements(); } }
public void EnableCorrectScreenElements() { PanelCustomerInformation.Visible = true; PanelOrderLines.Visible = false; PanelOrderLines.Enabled = false; PanelCustomerInformation.Enabled = false; PanelInvoice.Visible = false; PanelOrderSummary.Visible = false; PanelInvoice.Enabled = false; PanelOrderSummary.Enabled = false; ButtonContinue.Visible = false; ButtonRevert.Visible = false; ButtonDestroyOrderAndBack.Visible = false; ButtonNewOrder.Visible = false; ButtonPrintAndProcess.Visible = false; ButtonRefresh.Visible = false; CheckBoxProFormaInvoice.Visible = (LabelRentMode.Text != "Cash"); TextBoxInvoiceDiscount.Enabled = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked); TextBoxBail.Enabled = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked); TextBoxInvoiceNote.Enabled = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked); switch (CurrentPageNr) { case 1: PanelCustomerInformation.Enabled = true; ButtonContinue.Visible = true; break; case 2: if (CheckBoxDatesOpenEndDate.Checked) { CalendarControlEnd.SelectedDateTime = new DateTime(2100, 1, 1); } if (TextBox_DriverId.Text == "") { CurrentPageNr--; EnableCorrectScreenElements(); Common.InformUser(Page, "Geef een identificatie van de verhuurder op aub. Bv naam en rijbewijs met rijbewijs nummer, of bedrijfspasnaam en bedrijfspasnummer."); break; } ButtonContinue.Visible = true; ButtonRevert.Visible = true; PanelOrderLines.Enabled = true; PanelOrderLines.Visible = true; WebUserControlRentMaterials1.StartRentDate = CalendarControlStart.SelectedDateTime; WebUserControlRentMaterials1.EndRentDate = CalendarControlEnd.SelectedDateTime; if (CheckBoxDatesOpenEndDate.Checked) { WebUserControlRentMaterials1.EndRentDate = new DateTime(2100, 1, 1); } WebUserControlRentMaterials1.CustomerID = new Guid(DropDownListCustomers.SelectedValue); WebUserControlRentMaterials1.LocationID = new Guid(DropDownListLocations.SelectedValue); ButtonContinue.Visible = WebUserControlRentMaterials1.HasOrderLines(); break; case 3: ButtonPrintAndProcess.Visible = true; ButtonRevert.Visible = true; PanelOrderLines.Visible = true; PanelOrderSummary.Enabled = true; PanelOrderSummary.Visible = true; RecalcTotals(); ButtonPrintAndProcess.Visible = LabelTotalItemsValue.Text != "0"; break; case 4: PanelOrderLines.Visible = true; PanelOrderSummary.Visible = true; ButtonDestroyOrderAndBack.Visible = true; ButtonNewOrder.Visible = true; PanelInvoice.Visible = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked);; PanelInvoice.Enabled = true; // show reports. Invoice & contracts. FrameShowInvoiceA.Attributes["src"] = ""; FrameShowInvoiceB.Attributes["src"] = ""; FrameShowInvoiceA.Visible = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked); FrameShowInvoiceB.Visible = (LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked); if ((LabelRentMode.Text == "Cash") || (CheckBoxProFormaInvoice.Checked)) { FrameShowInvoiceA.Attributes["src"] = "WebFormPopup.aspx?UC=ShowReport&d=DataSetInvoice&r=ReportInvoiceRentA4&Id=" + CurrentRentInvoiceId.ToString(); FrameShowInvoiceB.Attributes["src"] = "WebFormPopup.aspx?UC=ShowReport&d=DataSetRent&r=ReportRentContractsA4&Id=" + CurrentRentInvoiceId.ToString(); } break; } }