<?php
// DOCUMENT DETAILS ///////////////////////////////////////////////////////////////////////////////
refreshReportStatus('extractMainDataFromDb', 'updateDocumentDetails', 0);

// update the document series code
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_docSeries, 'doc_seriesCode', 'doc_seriesId', 'code');

// update the document type name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("doc_typeName", "doc_typeCode", \App\Config\PaymentDocuments::getInstance()->getList());
$reportCopyInfo->populate();

// update the document responsible user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'doc_respUserName', 'doc_respUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the document reponsible office name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_offices, 'doc_respOfficeName', 'doc_respOfficeId', 'name');

// update the document reponsible department name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_departments, 'doc_respDepartmentName', 'doc_respDepartmentId', 'name');

// update the document add user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'doc_addUserName', 'doc_addUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the document update user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'doc_updateUserName', 'doc_updateUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the document block user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'doc_blockUserName', 'doc_blockUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update document bank details
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addJoinTable($DBTRd_agencyBankAccounts,	'bankAcc',   'rep.doc_bankAccountId=bankAcc.id', 	'LEFT');
$reportCopyInfo->addJoinTable($DBTRd_banks,					'bank',  	 'bankAcc.idBank=bank.id', 				'LEFT');

$reportCopyInfo->setStructureColumns([
	'doc_bankAccount' 		=> 'bankAcc.account',
	'doc_bankId' 			=> 'bankAcc.idBank',
	'doc_bankName'			=> 'bank.nameStd',
]);

$reportCopyInfo->populate();

// IMPORTED DOCUMENTS SYSTEM DATA /////////////////////////////////////////////////////////////////
refreshReportStatus('extractMainDataFromDb', 'updateImpDocumentDetails', 0);

// update the imported system name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_importedDocSystems, 'impDoc_externalSystemName', 'impDoc_externalSystemId', 'name');

// update the imported doc process status name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("impDoc_processStatusName", "impDoc_processStatusCode", (Array)$_LANG['importedDocuments']['statusName']);
$reportCopyInfo->populate();


// INVOICE DATA ///////////////////////////////////////////////////////////////////////////////////
refreshReportStatus('extractMainDataFromDb', 'updateInvoiceDetails', 0);

// update the operational name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("inv_statusOpName", "inv_statusOpCode", (Array)$_LANG['supplierInvoices']['statusOp']);
$reportCopyInfo->populate();

// update the financial name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addCaseStructureColumn("inv_statusFinName", "inv_statusFinCode", (Array)$_LANG['supplierInvoices']['statusFin']);
$reportCopyInfo->populate();

// update the invoice responsible user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'inv_userName', 'inv_userId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the invoice reponsible office name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_offices, 'inv_officeName', 'inv_officeId', 'name');

// update the invoice add user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'inv_addUserName', 'inv_addUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

// update the invoice issue user name
$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $availableTableColumns);
$reportCopyInfo->populateSimple($DBTRd_users, 'inv_blockUserName', 'inv_blockUserId', "CONCAT(joinTable.lastName, ' ', joinTable.firstName)");

$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $availableTableColumns);
$reportCopyInfo->addJoinTable($DBTRd_suppliers,          'supp',    			'rep.inv_supplierId=supp.id',				'INNER');

$reportCopyInfo->setStructureColumns([
	'inv_supplierName'	=> 					'supp.alias',
	'inv_supplierRegNo'	=> 					'supp.regNo',
	'inv_supplierFiscalCode' => 			'supp.fiscalCode',
]);
$reportCopyInfo->populate();
