Fiş BeforeSave Script

Fiş BeforeSave Script

if(this.recordService.component.mode.value === 'insert'){
  this.allGrids['accounting-receipt-detail'].grid.agGrid.api.forEachNode(rowNode =>{
    if (rowNode.data.ID){
       throw new Error(angus.languageService.staticTranslator.translate('Problem is occured while record cloning. Try cloning again.'));
    } 
  });
      
}

if(!this.recordService.lastData){
   this.allFormControls['STATUS'].setValue(2);
}
if (this.allGrids['accounting-receipt-detail'].api.getDisplayedRowCount() === 0)
        throw new Error(angus.languageService.staticTranslator.translate('You cannot save the accounting slip without a line!')); 
if (this.recordService.lastData && this.recordService.lastData.STATUS == 3){
  throw new Error(angus.languageService.staticTranslator.translate('This fiche is approved, you cannot make changes'));
}
if (this.recordService.lastData && this.recordService.lastData.INVOICEID && this.recordService.formGroup.controls.SOURCETYPEID.value == 6 && (!angus.api.tenant.ACCOUNTING_ALLOWCHANGE_STOCKINVOICEACCRECEIPT)) //stok faturası ise
{
  throw new Error(angus.languageService.staticTranslator.translate('Source is invoice, you cannot make changes'));
}

if (this.recordService.lastData && this.recordService.lastData.INVOICEID && this.recordService.formGroup.controls.SOURCETYPEID.value == 7 &&(!angus.api.tenant.ACCOUNTING_ALLOWCHANGE_SERVICEINVOICEACCRECEIPT))
{
  throw new Error(angus.languageService.staticTranslator.translate('Source is invoice, you cannot make changes'));
}

if (this.recordService.lastData && this.recordService.lastData.INVOICEID && this.recordService.formGroup.controls.SOURCETYPEID.value == 5 &&(!angus.api.tenant.ACCOUNTING_ALLOWCHANGE_HOTELINVOICEACCRECEIPT))
{
  throw new Error(angus.languageService.staticTranslator.translate('Source is invoice, you cannot make changes'));
}

if (this.recordService.lastData && this.recordService.lastData.COUNTINGID && (!angus.api.tenant.ACCOUNTING_ALLOWCHANGE_COUNTINGACCRECEIPT) )
{
  throw new Error(angus.languageService.staticTranslator.translate('Source is counting, you cannot make changes'));
}
if (this.allFormControls['RECEIPTNUMBER'].value != null && isNaN(this.allFormControls['RECEIPTNUMBER'].value)) 
{
  throw new Error(angus.languageService.staticTranslator.translate('Receipt Number, Please enter a Valid Count'));
}
let docTypeOther = this.allFormControls['DOCTYPEOTHER'].value;
let docType = this.allFormControls['DOCTYPE'].value;
if (docType == 8) {
  if (docTypeOther == undefined || docTypeOther == null || docTypeOther == ' ') {
    let msg = angus.languageService.dynamicTranslator.translate('Document Type Other Required!');
    throw msg;
  }
}
  
const rows = [];
this.allGrids['accounting-receipt-detail'].grid.agGrid.api.forEachNode(x =>{if (x.toBeDeleted !==true) rows.push(x)});
const fields = ['LOCALCREDIT', 'LOCALDEBIT'];
const totals = rows.reduce((acc, row) => {
  fields.forEach(field => {
    acc[field] = (acc[field] || 0) + row.data[field];
  })
  return acc;
}, {});
const deleteAllRows = [];
this.allGrids['accounting-receipt-detail'].grid.agGrid.api.forEachNode(x =>{if (x.toBeDeleted == true) deleteAllRows.push(x)});
console.log(totals, 'totals');
if(this.allGrids['accounting-receipt-detail'].api.getDisplayedRowCount() == deleteAllRows.length){
  let msg = angus.languageService.dynamicTranslator.translate('There are no valid lines');
  throw msg;
}
const controls = this.recordService.formGroup.controls;
controls.TOTALCREDIT.setValue(totals.LOCALCREDIT);
controls.TOTALDEBIT.setValue(totals.LOCALDEBIT);
if (Math.abs(totals.LOCALCREDIT-totals.LOCALDEBIT)>0.004) {
  let msg = angus.languageService.dynamicTranslator.translate('Total Debit and Credit Must Be Equal');
  throw msg;
}

let rowCountt = 0;
let valid = true;
this.recordService.grids['accounting-receipt-detail'].api.forEachNode(rowNode => {
     const data = rowNode.data;
     if(data.CHEQUEID && !data.CHEQUEACTIONID){
       let msg = angus.languageService.dynamicTranslator.translate('Please Select Check Transaction Type.');
       throw msg;
     }
      if(!controls.EXPENSEID.value && data.APPCARDID_EXR && !data.EXPENSEID){
       let msg = angus.languageService.dynamicTranslator.translate('Please Select Expense Center.');
       throw data.APPCARDID_ACC + ' ' + msg;
     }
     if(!rowNode.toBeDeleted)//SERKAN 2021-04-05 SATIR SİLİNDİ DEĞİLSE KONTROL YAP.
     {
        if (!data.APPCARDID || !(data.LOCALDEBIT > 0.004 || data.LOCALCREDIT > 0.004)) 
        {    
          valid = false;
        }
     }
     rowCountt++;
   });
  
if (!valid) {
  let msg = angus.languageService.dynamicTranslator.translate('Please select an account first and enter a debit or credit.');
  throw msg;
}

Last updated