Changeset 720
- Timestamp:
- Jan 3, 2015, 5:55:34 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/FormClasses.php
r719 r720 96 96 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'), 97 97 'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 98 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` )) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.99 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.` Value` > 0))'),98 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '. 99 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`Direction` = 1))'), 100 100 'Liabilities' => array('Type' => 'Integer', 'Caption' => 'Závazky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 101 'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value` )) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.102 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.` Value` < 0))'),101 'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '. 102 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoice`.`Direction` = -1))'), 103 103 'InvoiceBalance' => array('Type' => 'Integer', 'Caption' => 'Fakturační rozdíl', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 104 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` )) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.104 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '. 105 105 'AND (`FinanceInvoice`.`Time` >= `DateStart`))'), 106 106 ), -
trunk/Application/Version.php
r719 r720 1 1 <?php 2 2 3 $Revision = 7 19; // Subversion revision4 $DatabaseRevision = 7 19; // SQL structure revision3 $Revision = 720; // Subversion revision 4 $DatabaseRevision = 720; // SQL structure revision 5 5 $ReleaseTime = strtotime('2015-01-02'); -
trunk/Common/Setup/Updates.php
r719 r720 1055 1055 $Manager->Execute('UPDATE `FinanceOperation` SET `Direction` = -1 WHERE `Value` < 0 ;'); 1056 1056 $Manager->Execute('UPDATE `FinanceOperation` SET `Value` = -`Value` WHERE `Value` < 0 ;'); 1057 1057 // Set missing FinanceOperation DocumentLine according BillCode 1058 $Manager->Execute('UPDATE `FinanceOperation` SET `DocumentLine` = 1 WHERE (`BillCode` LIKE "PP%") AND (`DocumentLine` IS NULL)'); 1059 $Manager->Execute('UPDATE `FinanceOperation` SET `DocumentLine` = 2 WHERE (`BillCode` LIKE "VP%") AND (`DocumentLine` IS NULL)'); 1060 $Manager->Execute('UPDATE `FinanceOperation` SET `DocumentLine` = 3 WHERE (`BillCode` LIKE "BV%") AND (`DocumentLine` IS NULL)'); 1061 $Manager->Execute('UPDATE `FinanceOperation` SET `DocumentLine` = 4 WHERE (`BillCode` LIKE "PR%") AND (`DocumentLine` IS NULL)'); 1062 1058 1063 // IS menu item 1059 1064 $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Příjmy a výdaje"'); … … 1086 1091 "VALUES (NULL , 'Výdej z účtu', ".$DbRow['Id'].", '".$ActionId."', '1');"); 1087 1092 } 1093 } 1094 1095 function UpdateTo720($Manager) 1096 { 1097 $Manager->Execute('ALTER TABLE `FinanceInvoice` ADD `Direction` INT NOT NULL AFTER `TimePayment`;'); 1098 $Manager->Execute('UPDATE `FinanceInvoice` SET `Direction` = 1 WHERE `Value` >= 0 ;'); 1099 $Manager->Execute('UPDATE `FinanceInvoice` SET `Direction` = -1 WHERE `Value` < 0 ;'); 1100 $Manager->Execute('UPDATE `FinanceInvoice` SET `Value` = -`Value` WHERE `Value` < 0 ;'); 1101 // Set missing FinanceInvoice DocumentLine according BillCode 1102 $Manager->Execute('UPDATE `FinanceInvoice` SET `DocumentLine` = 5 WHERE (`BillCode` LIKE "PF%") AND (`DocumentLine` IS NULL)'); 1103 $Manager->Execute('UPDATE `FinanceInvoice` SET `DocumentLine` = 6 WHERE (`BillCode` LIKE "VF%") AND (`DocumentLine` IS NULL)'); 1104 1105 // IS menu item 1106 $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Závazky a pohledávky"'); 1107 if($DbResult->num_rows > 0) 1108 { 1109 $DbRow = $DbResult->fetch_assoc(); 1110 $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` , 1111 `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES ( 1112 NULL , "", "Příjaté", "1", "/is/?t=FinanceInvoiceIn&a=list", NULL , NULL , NULL , "1");'); 1113 $ActionId = $Manager->Database->insert_id; 1114 $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ". 1115 "VALUES (NULL , 'Přijaté', ".$DbRow['Id'].", '".$ActionId."', '1');"); 1116 1117 $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` , 1118 `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES ( 1119 NULL , "", "Vydané", "1", "/is/?t=FinanceInvoiceOut&a=list", NULL , NULL , NULL , "1");'); 1120 $ActionId = $Manager->Database->insert_id; 1121 $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ". 1122 "VALUES (NULL , 'Vydané', ".$DbRow['Id'].", '".$ActionId."', '1');"); 1123 } 1088 1124 } 1089 1125 … … 1145 1181 715 => array('Revision' => 718, 'Function' => 'UpdateTo718'), 1146 1182 718 => array('Revision' => 719, 'Function' => 'UpdateTo719'), 1183 719 => array('Revision' => 720, 'Function' => 'UpdateTo720'), 1147 1184 )); 1148 1185 } -
trunk/Modules/Finance/Bill.php
r719 r720 73 73 74 74 // If negative value => switch sides 75 if($Invoice[' Value'] < 0)75 if($Invoice['Direction'] == -1) 76 76 { 77 77 $Subject = $SubjectTo; 78 78 $SubjectTo = $SubjectFrom; 79 79 $SubjectFrom = $Subject; 80 foreach($InvoiceItems as $Index => $Item)81 {82 $InvoiceItems[$Index]['Price'] = -$InvoiceItems[$Index]['Price'];83 }84 80 } 85 81 … … 159 155 $MainSubjectAccount = $DbResult->fetch_assoc(); 160 156 161 //$Dodavka = array();162 //$DbResult = $this->Database->select('FinanceInvoiceItem', '*', 'FinanceInvoice='.$BillId);163 //while($Item = $DbResult->fetch_assoc())164 //{165 // $InvoiceItems[$Item['Id']] = $Item;166 //}167 157 $BooleanText = array('Ne', 'Ano'); 168 158 if($Operation['Direction'] == -1) -
trunk/Modules/Finance/Finance.php
r719 r720 186 186 while($Member = $DbResult->fetch_assoc()) 187 187 { 188 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE( SUM(-Value*Direction), 0) FROM FinanceOperation '.189 'WHERE Subject='.$Member['Subject'].') + (SELECT COALESCE( SUM(-Value), 0) FROM FinanceInvoice '.190 'WHERE Subject='.$Member['Subject'].')) asCash');188 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(-SUM(Value*Direction), 0) FROM FinanceOperation '. 189 'WHERE Subject='.$Member['Subject'].') + (SELECT COALESCE(-SUM(Value*Direction), 0) FROM FinanceInvoice '. 190 'WHERE Subject='.$Member['Subject'].')) AS Cash'); 191 191 $Cash = $DbResult2->fetch_row(); 192 192 $Cash = $Cash[0]; … … 277 277 'DefaultSortOrder' => 1, 278 278 'Items' => array( 279 'Direction' => array('Type' => 'TFinance Direction', 'Caption' => 'Směr', 'Default' => '1'),279 'Direction' => array('Type' => 'TFinanceOperationDirection', 'Caption' => 'Směr', 'Default' => '1'), 280 280 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''), 281 281 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''), … … 337 337 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true; 338 338 339 $this->System->FormManager->RegisterFormType('TFinance Direction', array(339 $this->System->FormManager->RegisterFormType('TFinanceOperationDirection', array( 340 340 'Type' => 'Enumeration', 341 341 'States' => array(-1 => 'Výdej', 1 => 'Příjem'), … … 347 347 'DefaultSortOrder' => 1, 348 348 'Items' => array( 349 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''), 349 'Direction' => array('Type' => 'TFinanceInvoiceDirection', 'Caption' => 'Směr', 'Default' => '1'), 350 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''), 350 351 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''), 351 352 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''), … … 367 368 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'), 368 369 )); 370 $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']); 371 $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury'; 372 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Default'] = -1; 373 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Hidden'] = true; 374 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Filter'] = true; 375 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_IN; 376 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Hidden'] = true; 377 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Filter'] = true; 378 379 $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']); 380 $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury'; 381 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Default'] = 1; 382 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Hidden'] = true; 383 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Filter'] = true; 384 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_OUT; 385 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Hidden'] = true; 386 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Filter'] = true; 387 388 $this->System->FormManager->RegisterFormType('TFinanceInvoiceDirection', array( 389 'Type' => 'Enumeration', 390 'States' => array(-1 => 'Příjem', 1 => 'Výdej'), 391 )); 392 369 393 $this->System->FormManager->RegisterClass('Company', array( 370 394 'Title' => 'Firma', -
trunk/Modules/Finance/Manage.php
r719 r720 50 50 { 51 51 if(!$this->System->User->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění'); 52 $SQL = 'SELECT Member.*, MemberPayment.MonthlyTotal AS Monthly, '.53 ' MemberPayment.Cash AS Cash, '.54 '(SELECT GROUP_CONCAT( Service.Name) FROM ServiceCustomerRel LEFT JOIN Service'.55 'ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer=Member.IdAND '.56 ' ServiceCustomerRel.Action IS NULL) AS ServicesNextMonth, '.57 'UNIX_TIMESTAMP( Member.BillingPeriodLastDate) AS LastDate, Subject.Name AS SubjectName, '.58 ' FinanceBillingPeriod.Name AS BillingPeriodName'.59 'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member JOIN Subject'.60 'ON Subject.Id=Member.Subject LEFT JOIN FinanceBillingPeriodON '.61 ' FinanceBillingPeriod.Id=Member.BillingPeriodNext WHERE (Member.Blocked= 0)'.62 'AND ( Member.BillingPeriodNext > 1) AND (MemberPayment.MonthlyTotal!= 0)';52 $SQL = 'SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `Monthly`, '. 53 '`MemberPayment`.`Cash` AS `Cash`, '. 54 '(SELECT GROUP_CONCAT(`Service`.`Name`) FROM `ServiceCustomerRel` LEFT JOIN `Service` '. 55 'ON `Service`.`Id`=`ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`=`Member`.`Id` AND '. 56 '`ServiceCustomerRel`.`Action` IS NULL) AS `ServicesNextMonth`, '. 57 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `LastDate`, `Subject`.`Name` AS `SubjectName`, '. 58 '`FinanceBillingPeriod`.`Name` AS `BillingPeriodName` '. 59 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` JOIN `Subject` '. 60 'ON `Subject`.`Id`=`Member`.`Subject` LEFT JOIN `FinanceBillingPeriod` ON '. 61 '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriodNext` WHERE (`Member`.`Blocked` = 0)'. 62 'AND (`Member`.`BillingPeriodNext` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)'; 63 63 64 64 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$SQL.') AS T'); … … 100 100 } 101 101 102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $ Items,102 function InsertInvoice($Subject, $TimeCreation, $TimeDue, $Direction, $Items, 103 103 $DocumentLine, $PeriodFrom, $PeriodTo) 104 104 { … … 109 109 $SumValue = 0; 110 110 foreach($Items as $Item) 111 $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']);111 $SumValue = $SumValue + ceil($Item['Price'] * $Item['Quantity']); 112 112 $this->Database->insert('FinanceInvoice', array( 113 'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation), 114 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 'BillCode' => $BillCode, 115 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo), 116 'Generate' => 1, 'DocumentLine' => $DocumentLine)); 113 'Subject' => $Subject, 'Time' => TimeToMysqlDateTime($TimeCreation), 114 'TimeDue' => TimeToMysqlDateTime($TimeDue), 'Value' => $SumValue, 115 'Direction' => $Direction, 'BillCode' => $BillCode, 116 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 'PeriodTo' => TimeToMysqlDate($PeriodTo), 117 'Generate' => 1, 'DocumentLine' => $DocumentLine)); 117 118 $InvoiceId = $this->Database->insert_id; 118 119 foreach($Items as $Item) … … 130 131 131 132 // Generuj účetní položky 132 $DbResult = $this->Database->query('SELECT Member.*, MemberPayment.MonthlyTotal AS MonthlyTotal, '.133 'UNIX_TIMESTAMP( Member.BillingPeriodLastDate), Subject.Name AS SubjectName,'.134 ' MemberPayment.MonthlyPlus AS MonthlyPlus'.135 'FROM MemberPayment JOIN Member ON Member.Id=MemberPayment.Member'.136 'JOIN Subject ON Subject.Id=Member.Subject');133 $DbResult = $this->Database->query('SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `MonthlyTotal`, '. 134 'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`), `Subject`.`Name` AS `SubjectName`,'. 135 '`MemberPayment`.`MonthlyPlus` AS `MonthlyPlus` '. 136 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` '. 137 'JOIN `Subject` ON `Subject`.`Id`=`Member`.`Subject`'); 137 138 while($Member = $DbResult->fetch_assoc()) 138 139 { … … 163 164 } 164 165 $PayPerPeriod = $MonthlyTotal * $Period['MonthCount']; 166 // We can't produce negative invoice except storno invoice. 167 // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction 168 // Other subject should invoice only possitive items. Negative items should be somehow removed. 169 if($MonthlyTotal >= 0) 170 $Direction = 1; // Standard out invoice 171 else { 172 $Direction = -1; // In case of negative total value generate reverse invoice for other subject 173 foreach($InvoiceItems as $Index => $Item) 174 $InvoiceItems[$Index]['Price'] = -$Item['Price']; 175 } 176 177 165 178 if($PayPerPeriod != 0) 166 179 { … … 168 181 $Output .= $TimePeriodText.': '.$MonthlyTotal.' * '.$Period['MonthCount'].' = '.$PayPerPeriod.'<br />'; 169 182 $this->InsertInvoice($Member['Subject'], time(), time() + 3600 * 24 * INVOICE_DUE_DAYS, 170 $ InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']);183 $Direction, $InvoiceItems, DOC_LINE_INVOICE_OUT, $Period['From'], $Period['To']); 171 184 172 185 $Output .= $this->SendPaymentEmail($Member['Id']); … … 227 240 $Output .= $Finance->LoadTariffs(); 228 241 $Output .= $Finance->RecalculateMemberPayment(); 229 230 // Celkovy prehled231 $DbResult = $this->Database->query('SELECT SUM(Product.SellPrice) AS Price FROM StockSerialNumber '.232 'JOIN Product ON StockSerialNumber.Product = Product.Id WHERE (StockSerialNumber.TimeElimination IS NULL) AND (StockSerialNumber.Segment IS NOT NULL)');233 $Row = $DbResult->fetch_row();234 $TotalDeviceCost = $Row[0];235 $Output .= 'Celková cena zařízení: Zařízení('.$TotalDeviceCost;236 242 237 243 $DbResult = $this->Database->query('SELECT SUM(NetworkDevice) FROM MemberPayment'); … … 279 285 $Output .= 'Aktualizuji služby....<br>'; 280 286 $this->TableUpdatePeriod('Service'); 287 281 288 // Update customer service selections 282 289 $Output .= 'Aktualizuji výběr služeb zákazníků....<br>'; … … 343 350 '<th style="border-style: solid; border-width: 1px; padding: 1px 5px 1px 5px; text-align: center; font-weight: bold;">Částka [Kč]</th></tr>'."\n"; 344 351 $DbResult = $this->Database->query('SELECT T1.* FROM ((SELECT Text, Time, (Value*Direction) AS Value, File FROM FinanceOperation WHERE (Subject='.$Member['Subject'].')) UNION ALL '. 345 '(SELECT CONCAT(`Text`, (SELECT GROUP_CONCAT(`Description` SEPARATOR "<br/>") FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`)) AS `Text`, Time, - Valueas Value, File FROM FinanceInvoice WHERE (Subject='.352 '(SELECT CONCAT(`Text`, (SELECT GROUP_CONCAT(`Description` SEPARATOR "<br/>") FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice` = `FinanceInvoice`.`Id`)) AS `Text`, Time, -(Value*Direction) as Value, File FROM FinanceInvoice WHERE (Subject='. 346 353 $Member['Subject'].')) ORDER BY Time DESC) AS T1 WHERE (T1.Time > "'.$Member['BillingPeriodLastDate'].'")'); 347 354 while($DbRow = $DbResult->fetch_assoc()) -
trunk/Modules/Finance/UserState.php
r719 r720 12 12 'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '. 13 13 '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '. 14 'Time, - Valueas Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')))';14 'Time, -(Value*Direction) as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')))'; 15 15 16 16 $Output = '<div style="text-align:center">Výpis finančních operací</div>'; … … 104 104 'FROM FinanceOperation WHERE (Subject='.$Subject['Id'].')) UNION ALL '. 105 105 '(SELECT (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoice=FinanceInvoice.Id) AS Text, '. 106 'Time, - Valueas Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')) ORDER BY Time DESC) AS T1';106 'Time, -(Value*Direction) as Value, File, BillCode, PeriodFrom, PeriodTo FROM FinanceInvoice WHERE (Subject='.$Subject['Id'].')) ORDER BY Time DESC) AS T1'; 107 107 $DbResult = $this->Database->query('SELECT SUM(T1.Value) AS Total FROM '.$UserOperationTableQuery); 108 108 $DbRow = $DbResult->fetch_array(); -
trunk/Modules/Finance/Zivnost.php
r719 r720 27 27 $Balance['Spend']['End'] = $Row[0] + 0; 28 28 29 $DbResult = $this->Database->query('SELECT SUM(Value ) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value > 0)');29 $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)'); 30 30 $Row = $DbResult->fetch_array(); 31 31 $Balance['Claims']['Start'] = $Row[0] + 0; 32 $DbResult = $this->Database->query('SELECT SUM(Value ) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value > 0)');32 $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)'); 33 33 $Row = $DbResult->fetch_array(); 34 34 $Balance['Claims']['End'] = $Row[0] + 0; 35 35 36 $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value < 0)');36 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)'); 37 37 $Row = $DbResult->fetch_array(); 38 38 $Balance['Liabilities']['Start'] = $Row[0] + 0; 39 $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value < 0)');39 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)'); 40 40 $Row = $DbResult->fetch_array(); 41 41 $Balance['Liabilities']['End'] = $Row[0] + 0; … … 206 206 $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '. 207 207 'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '. 208 'WHERE ( Value > 0) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].208 'WHERE (Direction = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart']. 209 209 '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time'); 210 210 while($Row = $DbResult->fetch_array()) 211 211 { 212 212 if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = ' '; 213 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td></tr>'; 213 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode']. 214 '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>'; 214 215 $Total += $Row['Value']; 215 216 } … … 228 229 $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '. 229 230 'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '. 230 'WHERE ( Value < 0) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].231 'WHERE (Direction = -1) AND (FinanceInvoice.Time >= "'.$Year['DateStart']. 231 232 '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time'); 232 233 while($Row = $DbResult->fetch_array()) … … 234 235 if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = ' '; 235 236 $Row['Value'] = $Row['Value'] * -1; 236 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td></tr>'; 237 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode']. 238 '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>'; 237 239 $Total += $Row['Value']; 238 240 } … … 245 247 $Output .= '<tr><th>Jméno</th><th>Závazky [Kč]</th><th>Pohledávky [Kč]</th><th>Příjmy [Kč]</th><th>Výdaje [Kč]</th><th>Stav účtu</th><th>Starý systém</th></tr>'; 246 248 $DbResult = $this->Database->query('SELECT Id, Name, 0 AS Cash, '. 247 '(SELECT SUM(T1.Value ) FROM FinanceInvoice AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.Value > 0)) as Claims, '.248 '(SELECT SUM(T2.Value ) FROM FinanceInvoice AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.Value > 0) AND (TimePayment IS NULL)) as OpenedClaims, '.249 '(SELECT -SUM(T3.Value ) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Value < 0)) as Liabilities, '.250 '(SELECT -SUM(T4.Value ) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Value < 0) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.249 '(SELECT SUM(T1.Value*T1.Direction) FROM FinanceInvoice AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.Direction = 1)) as Claims, '. 250 '(SELECT SUM(T2.Value*T2.Direction) FROM FinanceInvoice AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '. 251 '(SELECT -SUM(T3.Value*T3.Direction) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Direction = -1)) as Liabilities, '. 252 '(SELECT -SUM(T4.Value*T4.Direction) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Direction = -1) AND (TimePayment IS NULL)) AS OpenedLiabilities, '. 251 253 '(SELECT SUM(T5.Value*T5.Direction) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.Direction = 1)) AS Gains, '. 252 254 '(SELECT SUM(T6.Value*T6.Direction) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.Direction = -1)) AS Spends '. … … 287 289 $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">'; 288 290 $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th><th>Doklad</th></tr>'; 289 $DbResult = $this->Database->select('FinanceInvoice', '*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text', 'Subject='.$_GET['Id'].' ORDER BY Time'); 291 $DbResult = $this->Database->select('FinanceInvoice', '*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '. 292 'FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text', 293 'Subject='.$_GET['Id'].' ORDER BY Time'); 290 294 while($Row = $DbResult->fetch_array()) 291 295 { 292 296 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.HumanDate($Row['TimePayment']). 293 '</td><td>'.$Row['Text'].'</td><td>'. ($Row['Value']).'</td><td>'.$Row['BillCode'].'</td></tr>';297 '</td><td>'.$Row['Text'].'</td><td>'.ceil($Row['Value'] * $Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>'; 294 298 } 295 299 $Output .= '</table></td></tr></table>'; … … 305 309 $Output .= '</table>';*/ 306 310 307 $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceInvoice.Value ) '.308 'FROM FinanceInvoice WHERE FinanceInvoice.Subject = Subject.IdAND '.309 ' FinanceInvoice.Value > 0) as Claims, (SELECT SUM(FinanceInvoice.Value) '.310 'FROM FinanceInvoice WHERE FinanceInvoice.Subject = Subject.Id AND'.311 'FinanceInvoice. Value > 0 AND TimePayment IS NULL) as OpenedClaims, '.312 '(SELECT SUM(FinanceInvoice.Value ) FROM FinanceInvoice '.313 'WHERE FinanceInvoice.Subject = Subject.Id AND FinanceInvoice.Value < 0) AS '.311 $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '. 312 'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND '. 313 '(FinanceInvoice.Direction = 1)) as Claims, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '. 314 'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND ('. 315 'FinanceInvoice.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '. 316 '(SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) FROM FinanceInvoice '. 317 'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1)) AS '. 314 318 'Liabilities, (SELECT SUM(FinanceInvoice.Value) FROM FinanceInvoice '. 315 'WHERE FinanceInvoice.Subject = Subject.Id AND FinanceInvoice.Value < 0 '. 316 'AND TimePayment IS NULL) as OpenedLiabilities, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) '. 319 'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1) '. 320 'AND (TimePayment IS NULL)) AS OpenedLiabilities, '. 321 '(SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) '. 317 322 'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = 1) '. 318 323 'AS Gains, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) FROM FinanceOperation WHERE '. -
trunk/Modules/Subject/Subject.php
r719 r720 37 37 'Payment' => array('Type' => 'Float', 'Caption' => 'Placení', 'Default' => '', 38 38 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL((SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '. 39 'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` ) FROM `FinanceInvoice` '.39 'WHERE `FinanceOperation`.`Subject`=#Id), 0) - IFNULL((SELECT SUM(`FinanceInvoice`.`Value` * `FinanceInvoice`.`Direction`) FROM `FinanceInvoice` '. 40 40 'WHERE `FinanceInvoice`.`Subject`=#Id), 0)'), 41 41 ),
Note:
See TracChangeset
for help on using the changeset viewer.