import { Component, OnInit, NgZone, ElementRef } from '@angular/core'; import { ActivatedRoute, Router } from "@angular/router"; import { FormBuilder, FormGroup, Validators} from '@angular/forms'; import { PricingSummaryAdministration } from "../../../../../models/admin/company/pricing-summary-administration/pricing-summary-administration"; import { PricingSummaryAdministrationService } from '../../../../../services/admin/company/pricing-summary-administration/pricing-summary-administration.service'; import { CommonService } from '../../../../../services/common.service'; import { Subject } from 'rxjs'; import { CommonlistRequest, CommonListResponse } from '../../../../../models/shared/commonlist'; import { CustomValidator } from '../../../../../core/custom-validator'; @Component({ selector: 'app-pricing-summary-administration-add', templateUrl: './pricing-summary-administration-add.component.html', styleUrls: ['./pricing-summary-administration-add.component.css'] }) export class PricingSummaryAdministrationAddComponent implements OnInit { modelPricingSummary = new PricingSummaryAdministration(); PricingSummaryAPIResponse: any; PricingSummaryForm: FormGroup; lstCampaign: CommonListResponse[];; lstShipping: CommonListResponse[];; lstCulture: CommonListResponse[];; _paramId: number = 0; companyid: number = 1; dtOptions: any = {} dtTrigger: Subject = new Subject(); commonlistRequest = new CommonlistRequest(); commonListResponse: CommonListResponse[]; tinyMCEInitOptions; previewContent: string = ''; showModal: boolean = false; previewModal; default: string = ''; isShowDiv = true; constructor( private formBuilder: FormBuilder, private route: ActivatedRoute, private router: Router, private service: PricingSummaryAdministrationService, private common: CommonService, private ngZone: NgZone, private elementRef: ElementRef ) { } ngOnInit(): void { this.tinyMCEInitOptions = this.common.tinyMCEOptionsWithHeightWidth(100, 500); this._paramId = Number(this.route.snapshot.params.id); this.setFormBuilder(); this.getMultipleDropdown(); this.getPricingListById(); } showPreviewModal() { this.showModal = true; this.previewContent = this.PricingSummaryForm.get("LoadContent").value; this.previewModal = { content: this.previewContent, file:'', fileFormat:'' } } getModalToggleValue(data) { this.showModal = data.toggle; } getPricingListById() { if (this._paramId == 0) { this.setAddForm(); } else { this.isShowDiv = false; this.service.getPricingById(this._paramId, data => { this.PricingSummaryAPIResponse = data; this.modelPricingSummary = this.PricingSummaryAPIResponse.objResponse.responseContent; this.setEditForm(); }, (error) => { console.error('Error: ' + error); return error(error); }); } } getMultipleDropdown() { this.commonlistRequest.IsFromCommon = true; this.commonlistRequest.strCategory = "Country,Campaign,Culture"; this.common.CommonList(this.commonlistRequest, data => { this.commonListResponse = data.objResponse.responseContent; this.lstCulture = this.commonListResponse.filter(x => x.Category == "Culture"); this.lstShipping = this.commonListResponse.filter(x => x.Category == "Country"); this.lstCampaign = this.commonListResponse.filter(x => x.Category == "Campaign"); }, (error) => { console.error('Error: ' + error); return error(error); }); } setAddForm() { this.PricingSummaryForm.setValue({ CompanyId: this.companyid, Name: '', CampaignId:'', ShippingtocountryId:'', CultureId:'', IsForSignatureorders: false, IsForComponents: true, IsLoadFromComponent: false, LoadContent:'', LoadComponent: '' }); } setFormBuilder() { this.PricingSummaryForm = this.formBuilder.group({ CompanyId: [''], Name: ['', [Validators.required, CustomValidator.noWhitespaceValidator, Validators.maxLength(50)]], CampaignId: ['', Validators.required], CultureId: ['', Validators.required], ShippingtocountryId: ['', Validators.required], IsForSignatureorders: [false], IsForComponents: [false], IsLoadFromComponent: [false], LoadContent:[''], LoadComponent: [''] }); } setEditForm() { this.PricingSummaryForm.setValue({ CompanyId: this.companyid, Name: this.modelPricingSummary.Name == null ? "" : this.modelPricingSummary.Name, CampaignId: this.modelPricingSummary.CampaignId, ShippingtocountryId: this.modelPricingSummary.ShippingtocountryId, CultureId: this.modelPricingSummary.CultureId, IsForSignatureorders: this.modelPricingSummary.IsForSignatureorders, IsForComponents: this.modelPricingSummary.IsForComponents, IsLoadFromComponent: this.modelPricingSummary.IsLoadFromComponent, LoadContent: this.modelPricingSummary.LoadContent, LoadComponent: '' }); } navigateTo(url) { this.router.navigate([url]); } submitform() { if (this.PricingSummaryForm.valid) { this.modelPricingSummary = this.PricingSummaryForm.value; this.setModelBeforeSubmit(); this.service.savePricing(this.modelPricingSummary, data => { this.PricingSummaryAPIResponse = data; if (this.PricingSummaryAPIResponse.objResponse.statusCode == "200") { this.ngZone.run(() => this.navigateTo('/admin/admin-company/pricing-summary-administration-list')); this.common.showSuccess("Pricing Summary changes applied successfully.", "Success") } else { this.common.showError("Transaction not completed.", "Transaction Fail") } }, (error) => { console.error('Error: ' + error); return error(error); }); } else { this.common.showError("Please fill required fields.", "Validation Alert!") this.common.validateAllFormFields(this.PricingSummaryForm); this.common.validationfocus(this.PricingSummaryForm, this.elementRef); } } setModelBeforeSubmit() { this.modelPricingSummary.CompanyId = Number(this.companyid); this.modelPricingSummary.PricingSummaryId = Number(this._paramId); this.modelPricingSummary.Name = String(this.modelPricingSummary.Name); this.modelPricingSummary.CampaignId = Number(this.modelPricingSummary.CampaignId); this.modelPricingSummary.ShippingtocountryId = Number(this.modelPricingSummary.ShippingtocountryId); this.modelPricingSummary.CultureId = Number(this.modelPricingSummary.CultureId); this.modelPricingSummary.IsForSignatureorders = Boolean(Number(this.modelPricingSummary.IsForSignatureorders)); this.modelPricingSummary.IsForComponents = Boolean(Number(this.modelPricingSummary.IsForComponents)); this.modelPricingSummary.IsLoadFromComponent = Boolean(Number(this.modelPricingSummary.IsLoadFromComponent)); this.modelPricingSummary.LoadContent = String(this.modelPricingSummary.LoadContent); } displayFieldCss(field: string, ctrlType: string) { if (ctrlType.toLowerCase() == "txt") { return { 'plain-valid': this.PricingSummaryForm.get(field).valid, 'is-invalid': (this.PricingSummaryForm.get(field).invalid && (this.PricingSummaryForm.get(field).dirty || this.PricingSummaryForm.get(field).touched)) }; } else { return { 'plain-valid': this.PricingSummaryForm.get(field).valid, 'plain-invalid': (this.PricingSummaryForm.get(field).invalid && (this.PricingSummaryForm.get(field).dirty || this.PricingSummaryForm.get(field).touched)) }; } } LoadComponentSample() { this.isShowDiv = false; if (this.modelPricingSummary.IsLoadFromComponent == true) { this.PricingSummaryForm.controls.IsLoadFromComponent.setValue(true); this.PricingSummaryForm.controls.LoadContent.setValue(this.modelPricingSummary.LoadContent); } else { this.previewContent = ""; this.previewContent = "
Components
 
[[ComponentsPrice]]
Adjustments
 
[[PricingAdjustment]]
Discounted Price
 
[[DiscountedPrice]]
Estimated Weight (lbs)
 
[[Weight]]
Crating Weight (lbs)
 
[[CratingWeight]]
Distance
 
[[Distance]]
Truck Tarp Fee
 
[[TruckTarpFee]]
Freight
 
[[Freight]]
Packaging Fee
 
[[PackagingFee]]
Estimated Tax
Applicable tax will be added at the time of invoice
Not Included
 
Total
 
[[Total]]
NOTE:
 
The Terms and Conditions governing this contract are those contained in the section entitled 'Uniform Terms and Conditions', and in addition. The parties hereto acknowledge and agree that [INSERT COMPANY NAME] is only required to furnish materials in accordance with this purchase order and the referenced terms and conditions as noted on the previous pages.
 
TERMS OF PAYMENT:
 
With payment to be made in [INSERT LOCATION HERE] in accordance with terms to be established at the sole discretion of [INSERT COMPANY NAME] Credit Department.
 

THIS CONTRACT IS NOT VALID UNLESS SIGNED AND ACCEPTED BY A REPRESENTATIVE OF [INSERT COMPANY NAME]

 
BUYER'S/CUSTOMER'S ACCEPTANCE OF PURCHASE ORDER:
 
The prices and conditions are satisfactory and hereby accepted, subject to the terms and conditions set forth above. You are authorized to do the work as specified. Payment will be made as outlined above.
 

 
Accepted on:  
  Date
 
Accepted By:  
  Print Name
 
 
 
  Signature
 
 
 
  Title

 
[INSERT COMPANY NAME] ACCEPTANCE OF ORDER:

 
Accepted on:  
  Date
 
Accepted By:  
  Print Name
 
 
 
  Signature
 
 
 
  Title

 
"; this.PricingSummaryForm.controls.IsLoadFromComponent.setValue(true); this.PricingSummaryForm.controls.LoadContent.setValue(this.previewContent); } //this.PricingSummaryForm.patchValue({ LoadComponent: this.previewContent }); } LoadBuildingSample() { this.isShowDiv = false; if (this.modelPricingSummary.IsLoadFromComponent == false && this.modelPricingSummary.LoadContent != '') { this.PricingSummaryForm.controls.IsLoadFromComponent.setValue(false); this.PricingSummaryForm.controls.LoadContent.setValue(this.modelPricingSummary.LoadContent); } else { this.previewContent = ""; this.previewContent = "
Estimated Weight (lbs)
 
[[Weight]]
Weathertightness Warranty
 
[[WTW]]
Distance
 
[[Distance]]
Truck Tarp Fee
 
[[TruckTarpFee]]
Freight
 
[[Freight]]
Insulation Freight
 
[[InsulationFreight]]
Estimated Tax
Applicable tax will be added at the time of invoice
Not Included
 
3 Week Shipping
 
[[3WeekShipping]]
Documents Fees
 
[[DocumentsFee]]
Express Delivery Fee
 
[[ExpressDeliveryFee]]
Total
 
[[Total]]
NOTE:
 
The Terms and Conditions governing this contract are those contained in the section entitled 'Uniform Terms and Conditions', and in addition. The parties hereto acknowledge and agree that [INSERT COMPANY NAME] is only required to furnish materials in accordance with this purchase order and the referenced terms and conditions as noted on the previous pages.
 
TERMS OF PAYMENT:
 
With payment to be made in [INSERT LOCATION HERE] in accordance with terms to be established at the sole discretion of [INSERT COMPANY NAME] Credit Department.
 

THIS CONTRACT IS NOT VALID UNLESS SIGNED AND ACCEPTED BY A REPRESENTATIVE OF [INSERT COMPANY NAME]

 
BUYER'S/CUSTOMER'S ACCEPTANCE OF PURCHASE ORDER:
 
The prices and conditions are satisfactory and hereby accepted, subject to the terms and conditions set forth above. You are authorized to do the work as specified. Payment will be made as outlined above.
 

 
Accepted on:  
  Date
 
Accepted By:  
  Print Name
 
 
 
  Signature
 
 
 
  Title

 
[INSERT COMPANY NAME] ACCEPTANCE OF ORDER:

 
Accepted on:  
  Date
 
Accepted By:  
  Print Name
 
 
 
  Signature
 
 
 
  Title

 
"; this.PricingSummaryForm.controls.IsLoadFromComponent.setValue(false); this.PricingSummaryForm.controls.LoadContent.setValue(this.previewContent); } //this.PricingSummaryForm.patchValue({ LoadComponent: this.previewContent }); } }