<?php
 if ($R['submitFirstTimeCashBookForm']) { $OK=1; if (!$R['firstTimeCashBook']['date']) { $showMessage['warning'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['missingDate']; $OK=0; } else { $firstTimeCashBookDate=standard2mysqlDateConversion($R['firstTimeCashBook']['date']); if (!$firstTimeCashBookDate) { $showMessage['warning'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['invalidDate']; $OK=0; } else { if ($firstTimeCashBookDate>TODAY_ISO) { $showMessage['warning'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['dateInFuture']; $OK=0; } } } if (!$R['firstTimeCashBook']) { $showMessage['error'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['missingValuesFromRequest']; $OK=0; } else { foreach ($currencyArray as $thisCurrency) { if (!is_numeric($R['firstTimeCashBook']['initialValue'][$thisCurrency]) or $R['firstTimeCashBook']['initialValue'][$thisCurrency]<0) { $showMessage['warning'] = sprintf($_LANG['cashBookView']['saveFirstTotals']['messages']['invalidInitialValue'], $thisCurrency); $OK=0; } } } $lastClosedDate=Cashbook::getLastClosedBalanceDate($R['idOffice']); if ($lastClosedDate) { $showMessage['warning'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['firstTotalsExist']; $OK=0; } if ($OK) { $sqlValues=array(); foreach ($currencyArray as $thisCurrency) { $sqlValues[]="(". "'".$R['idOffice']."', '".$firstTimeCashBookDate."', ". "'".$thisCurrency."', '".round($R['firstTimeCashBook']['initialValue'][$thisCurrency], 2)."', ". "'".$S['auth']['idUser']."', '".TIMESTAMP."'
			)"; } if ($sqlValues) { $updateCashBookSQL="
				INSERT INTO `$DBTCashBook` (`idOffice`, `closedDate`, `currency`, `totalValue`, `idUpdateUser`, `lastUpdateTime`)
				VALUES ".implode(", ", $sqlValues) ; $updateCashBook=$db->Execute($updateCashBookSQL); if (!$updateCashBook) { $showMessage['error'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['saveFirstTotalsError']; $OK=0; writeLog("Could not update initial cashBook (offices totals). SQL: ".$updateCashBookSQL, 'events', 10); } } } if ($OK) { $showMessage['success'] = $_LANG['cashBookView']['saveFirstTotals']['messages']['saveFirstTotalsSuccess']; $userTrailItem->updateActionOld('cashBook_saveFirstTotalsOk'); $userTrailItem->updateExtraDataOld(array('date'=>$firstTimeCashBookDate)); } } 