phpBMS

Changeset 693 for trunk/phpbms/modules

Show
Ignore:
Timestamp:
12/31/09 13:36:45 (2 years ago)
Author:
brieb
Message:
  • Introduced administratively changeable settings to indvidual reports
  • Modified all reports to work with new settings system
  • Altered invoice and line item total reports to accept parameters from reportsettings: You can now bypass the grouping/column dialog by providing the infrmation administratively
  • Altered all sales order PDF reports to accept parameters from reportsettings: You can now administratively change certain aspects of the print outs, including what parts of the top of the report to show, and what to title the report
  • Altered label reports to accept parameters from reportsettings: printed data as well

as label measurements and layout are now defined by administratively

  • Altered export and tableprint reports to accept parameters from reportsettings: You can specify individual columns and from table instead of just the defaults (all fields, main table only)
  • Added var_dump-esque 'debug' function for development purposes to common functions
  • Integrated FPDI functionality with sales order PDF reports: It is now possible to use a PDF saved in the files table as a background template for your invoices (e.g. watermarks)
Location:
trunk/phpbms/modules
Files:
2 added
15 removed
22 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/include/reports.php

    r583 r693  
    3838*/ 
    3939if(class_exists("phpbmsTable")) { 
    40         class reports extends phpbmsTable{ 
    41  
    42                 var $_availableTabledefUUIDs = NULL; 
    43                 var $_availableRoleUUIDs = NULL; 
    44  
    45                 function getDefaults(){ 
    46                         $therecord = parent::getDefaults(); 
    47  
    48                         $therecord["type"]="report"; 
    49                         $therecord["uuid"] = uuid("reports:"); 
    50  
    51                         return $therecord; 
    52  
    53                 } 
    54  
    55  
    56                 function verifyVariables($variables){ 
    57  
    58                         //cannot be table default ("") 
    59                         if(isset($variables["reportfile"])){ 
    60                                 if($variables["reportfile"] === "" || $variables["reportfile"] === NULL) 
    61                                         $this->verifyErrors[] = "The `reportfile` field must not be blank."; 
    62                         }else 
    63                                 $this->verifyErrors[] = "The `reportfile` field must be set."; 
    64  
    65                         //Table default (NULL) OK 
    66                         if(isset($variables["type"])) 
    67                                 if($variables["type"] !== "")//don't care if it's "" 
    68                                         switch($variables["type"]){ 
    69                                                 case "report": 
    70                                                 case "PDF Report": 
    71                                                 case "export": 
    72                                                         break; 
    73  
    74                                                 default: 
    75                                                         $this->verifyErrors[] = "The `type` field is not an accepted value.  It must be 'report', 'PDF Report', or 'export."; 
    76                                                 break; 
    77  
    78                                         }//end switch 
    79  
    80                         //Table Default ('') ok becuase it means report is globally available to any table 
    81                         if(isset($variables["tabledefid"])){ 
    82  
    83                                 if($this->_availableTabledefUUIDs === NULL){ 
    84                                         $this->_availableTabledefUUIDs = $this->_loadUUIDList("tabledefs"); 
    85                                         //add the global option 
    86                                         $this->_availableTabledefUUIDs[] = ""; 
    87                                 }//end if 
    88  
    89                                 if( !in_array((string)$variables["tabledefid"], $this->_availableTabledefUUIDs) ) 
    90                                         $this->verifyErrors[] = "The `tabledefid` field does not give an existing/acceptable table definition uuid."; 
    91  
    92                         }//end if 
    93  
    94                         //Table Default ('') ok becuase it means report is globally available to any user 
    95                         if(isset($variables["roleid"])){ 
    96  
    97                                 if($this->_availableRoleUUIDs === NULL){ 
    98                                         $this->_availableRoleUUIDs = $this->_loadUUIDList("roles"); 
    99                                         $this->_availableRoleUUIDs[] = ""; // for no role restrictions 
    100                                         $this->_availableRoleUUIDs[] = "Admin"; //for the Admin restriction 
    101                                 }//end if 
    102  
    103                                 if( !in_array((string)$variables["roleid"], $this->_availableRoleUUIDs) ) 
    104                                         $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable to role id number."; 
    105  
    106                         }//end if 
    107  
    108                         return parent::verifyVariables($variables); 
    109  
    110                 }//end method 
    111  
    112  
    113                 function displayTables($fieldname,$selectedid){ 
    114  
    115                         $querystatement="SELECT uuid, displayname FROM tabledefs ORDER BY displayname"; 
    116                         $thequery=$this->db->query($querystatement); 
    117  
    118                         echo "<select id=\"".$fieldname."\" name=\"".$fieldname."\">\n"; 
    119  
    120                         echo "<option value=\"\" "; 
    121                         if ($selectedid=="") echo "selected=\"selected\""; 
    122                         echo " style=\"font-weight:bold\">global</option>\n"; 
    123  
    124                         while($therecord=$this->db->fetchArray($thequery)){ 
    125                                 echo "  <option value=\"".$therecord["uuid"]."\""; 
    126                                         if($selectedid==$therecord["uuid"]) echo " selected=\"selected\""; 
    127                                 echo ">".$therecord["displayname"]."</option>\n"; 
    128                         } 
    129  
    130                         echo "</select>\n"; 
    131                 }//end method 
    132  
    133         }//end class 
     40    class reports extends phpbmsTable{ 
     41 
     42        var $_availableTabledefUUIDs = NULL; 
     43        var $_availableRoleUUIDs = NULL; 
     44 
     45        function getDefaults(){ 
     46 
     47            $therecord = parent::getDefaults(); 
     48 
     49            $therecord["type"] = "report"; 
     50 
     51            return $therecord; 
     52 
     53        }//end function getDefaults 
     54 
     55 
     56        function verifyVariables($variables){ 
     57 
     58            //cannot be table default ("") 
     59            if(isset($variables["reportfile"])){ 
     60                if($variables["reportfile"] === "" || $variables["reportfile"] === NULL) 
     61                    $this->verifyErrors[] = "The `reportfile` field must not be blank."; 
     62            }else 
     63                $this->verifyErrors[] = "The `reportfile` field must be set."; 
     64 
     65            //Table default (NULL) OK 
     66            if(isset($variables["type"])) 
     67                if($variables["type"] !== "")//don't care if it's "" 
     68                    switch($variables["type"]){ 
     69 
     70                            case "report": 
     71                            case "PDF Report": 
     72                            case "export": 
     73                                break; 
     74 
     75                            default: 
     76                                $this->verifyErrors[] = "The `type` field is not an accepted value.  It must be 'report', 'PDF Report', or 'export."; 
     77                            break; 
     78 
     79                    }//end switch 
     80 
     81            //Table Default ('') ok becuase it means report is globally available to any table 
     82            if(isset($variables["tabledefid"])){ 
     83 
     84                if($this->_availableTabledefUUIDs === NULL){ 
     85 
     86                    $this->_availableTabledefUUIDs = $this->_loadUUIDList("tabledefs"); 
     87 
     88                    //add the global option 
     89                    $this->_availableTabledefUUIDs[] = ""; 
     90 
     91                }//end if 
     92 
     93                if( !in_array((string)$variables["tabledefid"], $this->_availableTabledefUUIDs) ) 
     94                    $this->verifyErrors[] = "The `tabledefid` field does not give an existing/acceptable table definition uuid."; 
     95 
     96            }//end if 
     97 
     98            //Table Default ('') ok becuase it means report is globally available to any user 
     99            if(isset($variables["roleid"])){ 
     100 
     101                if($this->_availableRoleUUIDs === NULL){ 
     102 
     103                    $this->_availableRoleUUIDs = $this->_loadUUIDList("roles"); 
     104                    $this->_availableRoleUUIDs[] = ""; // for no role restrictions 
     105                    $this->_availableRoleUUIDs[] = "Admin"; //for the Admin restriction 
     106 
     107                }//end if 
     108 
     109                if( !in_array((string)$variables["roleid"], $this->_availableRoleUUIDs) ) 
     110                    $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable to role id number."; 
     111 
     112            }//end if 
     113 
     114            return parent::verifyVariables($variables); 
     115 
     116        }//end method 
     117 
     118 
     119        function insertRecord($variables, $createdby = NULL, $overrideID = false, $replace = false, $useUuid = false){ 
     120 
     121            $newid = parent::insertRecord($variables, $createdby, $overrideID, $replace, $useUuid); 
     122 
     123            $reportSettings = new reportSettings($this->db, $variables["uuid"]); 
     124            $reportSettings->createFromDefaults($variables["reportfile"]); 
     125 
     126            return $newid; 
     127 
     128        }//end method 
     129 
     130 
     131        function updateRecord($variables, $modifiedby = NULL, $useUuid = false){ 
     132 
     133            parent::updateRecord($variables, $modifiedby, $useUuid); 
     134 
     135            $reportSettings = new reportSettings($this->db, $variables["uuid"]); 
     136            $reportSettings->save($variables["rsDelList"], $variables["rsUpdates"], $variables["rsAdds"]); 
     137 
     138        }//end method updateRecord 
     139 
     140 
     141        function displayTables($fieldname,$selectedid){ 
     142 
     143            $querystatement="SELECT uuid, displayname FROM tabledefs ORDER BY displayname"; 
     144            $thequery=$this->db->query($querystatement); 
     145 
     146            echo "<select id=\"".$fieldname."\" name=\"".$fieldname."\">\n"; 
     147 
     148            echo "<option value=\"\" "; 
     149            if ($selectedid=="") echo "selected=\"selected\""; 
     150            echo " style=\"font-weight:bold\">global</option>\n"; 
     151 
     152            while($therecord=$this->db->fetchArray($thequery)){ 
     153                    echo "      <option value=\"".$therecord["uuid"]."\""; 
     154                            if($selectedid==$therecord["uuid"]) echo " selected=\"selected\""; 
     155                    echo ">".$therecord["displayname"]."</option>\n"; 
     156            } 
     157 
     158            echo "</select>\n"; 
     159 
     160        }//end method 
     161 
     162 
     163        /** 
     164         * function displayFiles 
     165         * 
     166         * Displays a list of possible report filenames.  This includes 
     167         * all PHP files in the main report folder, as well as in the report 
     168         * folder of any loaded module 
     169         */ 
     170        function displayRerportFiles(){ 
     171 
     172            $files = array(); 
     173 
     174            $curDir = getcwd(); 
     175 
     176            chdir("../.."); 
     177 
     178            /** 
     179             * Load core reports 
     180             */ 
     181            if(file_exists("report") && is_dir("report")){ 
     182 
     183                $thedir = @ opendir("report"); 
     184 
     185                    while($entry = @ readdir($thedir)) 
     186                        if(@ strtolower(substr($entry, -4)) == ".php") 
     187                            $files[] = "report/".$entry; 
     188 
     189            }//endif 
     190 
     191            chdir("modules"); 
     192 
     193            /** 
     194             * Get loaded modules 
     195             */ 
     196            $querystatement = " 
     197                SELECT 
     198                    `name` 
     199                FROM 
     200                    `modules`"; 
     201 
     202            $queryresult = $this->db->query($querystatement); 
     203 
     204            while($therecord = $this->db->fetchArray($queryresult)){ 
     205 
     206                chdir($therecord["name"]); 
     207 
     208                $thedir = @ opendir("report"); 
     209 
     210                    while($entry = @ readdir($thedir)) 
     211                        if(@ strtolower(substr($entry, -4)) == ".php") 
     212                            $files[] = "modules/".$therecord["name"]."/report/".$entry; 
     213 
     214                chdir(".."); 
     215 
     216            }//endwhile 
     217 
     218            chdir($curDir); 
     219 
     220            ?><label for="reportfile">report file</label><br /> 
     221            <select id="reportfile" name="reportfile"> 
     222                <?php foreach($files as $filename){?> 
     223                    <option value="<?php echo $filename; ?>"><?php echo $filename; ?></option> 
     224                <?php }//endforeach?> 
     225            </select><?php 
     226 
     227        }//end function displayReportFiles 
     228 
     229    }//end class 
     230 
     231 
     232 
     233    /** 
     234     * handles retrieval, display and saving of report settings records 
     235     */ 
     236    class reportSettings{ 
     237 
     238        /** 
     239         * $db 
     240         * @var object the database object 
     241         */ 
     242        var $db; 
     243 
     244        /** 
     245         * $reportUUID 
     246         * @var string report UUID 
     247         */ 
     248        var $reportUUID; 
     249 
     250        /** 
     251         * $settingsQueryResult 
     252         * @var int query result reference 
     253         */ 
     254        var $settingsQueryResult; 
     255 
     256 
     257        /** 
     258         * function reportSettings 
     259         * 
     260         * Class initializer 
     261         * 
     262         * @param object $db database object 
     263         * @param string $reportUUID associated report's UUID 
     264         */ 
     265        function reportSettings($db, $reportUUID){ 
     266 
     267            $this->db = $db; 
     268            $this->reportUUID = $reportUUID; 
     269 
     270        }//end function reportSettings (init) 
     271 
     272 
     273        /** 
     274         * function get 
     275         * 
     276         * retrieves query result for all report settings asociated with report 
     277         */ 
     278        function get(){ 
     279 
     280            $querystatement = " 
     281                SELECT 
     282                    `id`, 
     283                    `name`, 
     284                    `value`, 
     285                    `type`, 
     286                    `required`, 
     287                    `description` 
     288                FROM 
     289                    `reportsettings` 
     290                WHERE 
     291                    `reportuuid` = '".$this->reportUUID."'"; 
     292 
     293            $this->settingsQueryResult = $this->db->query($querystatement); 
     294 
     295        }//end function get 
     296 
     297 
     298        /** 
     299         * function display 
     300         * 
     301         * Display all settings records one TR for each 
     302         */ 
     303        function display(){ 
     304 
     305            if($this->db->numRows($this->settingsQueryResult) == 0){ 
     306 
     307                ?><tr class="norecords" id="noSettings"><td colspan="5">No Settings</td></tr><?php 
     308 
     309                return; 
     310 
     311            }//endif 
     312 
     313            $row = 1; 
     314 
     315            while($therecord = $this->db->fetchArray($this->settingsQueryResult)){ 
     316 
     317                ?> 
     318                <tr class="qr<?php echo $row; ?> rsRows" id="rsExRow<?php echo $therecord["id"] ?>"> 
     319                    <td align="right"> 
     320                        <strong><?php echo formatVariable($therecord["name"]) ?></strong> 
     321                        <input class="rsNames" id="rsName<?php echo $therecord["id"]?>" type="hidden" value="<?php echo formatVariable($therecord["name"]) ?>" /> 
     322                    </td> 
     323                    <td> 
     324                        <?php if($therecord["type"] != "text") {?> 
     325                        <input class="rsValues" id="rsValue<?php echo $therecord["id"] ?>" type="text" size="32" value="<?php echo formatVariable(addcslashes($therecord["value"],"\\\n\t\r")) ?>" /> 
     326                        <?php } else { 
     327                            ?> 
     328                            <textarea class="rsValues" id="rsValue<?php echo $therecord["id"] ?>" rows="2" cols="29"><?php echo formatVariable(addcslashes($therecord["value"],"\\\n\t\r")) ?></textarea> 
     329                            <?php 
     330                        }?> 
     331                    </td> 
     332                    <td><?php echo formatVariable($therecord["type"]) ?></td> 
     333                    <td><?php echo formatVariable($therecord["description"]) ?></td> 
     334                    <td><?php 
     335                        if($therecord["required"] != 1){ 
     336 
     337                            ?><button type="button" id="rsDelButton<?php echo $therecord["id"]?>" class="graphicButtons buttonMinus rsDelButtons" title="Remove Setting"><span>-</span></button><?php 
     338 
     339                        }//endif 
     340                    ?></td> 
     341                </tr> 
     342                <?php 
     343 
     344                $row = ($row==1) ? 2 : 1; 
     345 
     346            }//endwhile 
     347 
     348        }//end function display 
     349 
     350 
     351        /** 
     352         * function save 
     353         * 
     354         * saves report settings changes 
     355         * 
     356         * @param string $delList JSON string of ids to be deleted 
     357         * @param string $updateList JSON string of updates to be made 
     358         * @param string $addList JSON string of name/value pairs to be added 
     359         */ 
     360        function save($delList, $updateList, $addList){ 
     361 
     362            $delList = json_decode(stripslashes($delList)); 
     363            if(count($delList)){ 
     364 
     365                $inClause = ""; 
     366 
     367                foreach($delList as $id){ 
     368 
     369                    $inClause .= ", ".$id; 
     370 
     371                }//endforeach 
     372 
     373                $deletestatement = " 
     374                    DELETE FROM 
     375                        `reportsettings` 
     376                    WHERE 
     377                        `id` IN (".substr($inClause, 1).")"; 
     378 
     379                $this->db->query($deletestatement); 
     380 
     381            }//endif 
     382 
     383            $updateList = str_replace("\n", "\\\\n", $updateList); 
     384            $updateList = str_replace("\r", "", $updateList); 
     385            $updateList = json_decode(stripslashes($updateList)); 
     386 
     387            foreach($updateList as $updateObj){ 
     388 
     389                $updatestatement = ' 
     390                    UPDATE 
     391                        `reportsettings` 
     392                    SET 
     393                        `value` = "'.mysql_real_escape_string($updateObj->value).'" 
     394                    WHERE 
     395                        `id` = '.((int) $updateObj->id); 
     396 
     397                $this->db->query($updatestatement); 
     398 
     399            }//endforeach 
     400 
     401 
     402            $addList = str_replace("\n", "\\\\n", $addList); 
     403            $addList = str_replace("\r", "", $addList); 
     404            $addList = json_decode(stripslashes($addList)); 
     405 
     406            foreach($addList as $addObj){ 
     407 
     408                $insertstatement = ' 
     409                    INSERT INTO 
     410                        `reportsettings` 
     411                    ( 
     412                        `reportuuid`, 
     413                        `name`, 
     414                         `value` 
     415                    ) VALUES ( 
     416                        "'.$this->reportUUID.'", 
     417                        "'.mysql_real_escape_string($addObj->name).'", 
     418                        "'.mysql_real_escape_string($addObj->value).'" 
     419                    )'; 
     420 
     421                $this->db->query($insertstatement); 
     422 
     423            }//endforeach 
     424 
     425        }//end function save 
     426 
     427 
     428        /** 
     429         * function createFromDefaults 
     430         * 
     431         * Creates reportsettings records for report based on defaults from the class 
     432         * instanciated by filename 
     433         * 
     434         * @param string $filename file name of report file to retrieve class from 
     435         */ 
     436        function createFromDefaults($filename){ 
     437 
     438            $addingReportRecord = true; 
     439            $noOutput = true; 
     440 
     441            include_once("report/report_class.php"); 
     442 
     443            include($filename); 
     444 
     445            if(!isset($reportClass)) 
     446                $error = new appError(200, "Report file is missing reportClass definition", "Report File Error"); 
     447            else 
     448                $report = new $reportClass($this->db, $this->reportUUID, "tbld:d595ef42-db9d-2233-1b9b-11dfd0db9cbb"); 
     449 
     450            $settings = $report->addingRecordDefaultSettings(); 
     451 
     452            $startInsertStatement = " 
     453                    INSERT INTO 
     454                        `reportsettings` 
     455                    ( 
     456                        `reportuuid`, 
     457                        `name`, 
     458                        `value`, 
     459                        `type`, 
     460                        `required`, 
     461                        `defaultvalue`, 
     462                        `description` 
     463                    ) VALUES ( 
     464                        '".$this->reportUUID."',"; 
     465 
     466            foreach($settings as $setting){ 
     467 
     468                $insertstatement = $startInsertStatement; 
     469                $insertstatement .= "'".$setting["name"]."', " ; 
     470                $insertstatement .= "'".$setting["defaultValue"]."', " ; 
     471                $insertstatement .= "'".$setting["type"]."', " ; 
     472                $insertstatement .= ((int) $setting["required"]).", " ; 
     473                $insertstatement .= "'".$setting["defaultValue"]."', " ; 
     474                $insertstatement .= "'".$setting["description"]."')" ; 
     475 
     476                $this->db->query($insertstatement); 
     477 
     478            }//endforeach 
     479 
     480        }//end function createFromDefaults 
     481 
     482    }//end class 
     483 
     484}//end if 
     485 
     486if(class_exists("searchFunctions")){ 
     487 
     488    class tabledefsSearchFunctions extends searchFunctions{ 
     489 
     490        function delete_record($useUUID = false){ 
     491 
     492            if(!$useUUID){ 
     493 
     494                $whereclause = $this->buildWhereClause(); 
     495                //support tables link to tabledefs using uuids not ids, so we must make sure that they are uuids. 
     496                $this->idsArray = getUuidArray($this->db, "tbld:d595ef42-db9d-2233-1b9b-11dfd0db9cbb", $this->idsArray); 
     497 
     498            }else 
     499                $whereclause = $this->buildWhereClause($this->maintable.".uuid"); 
     500 
     501            $linkedwhereclause = $this->buildWhereClause("reportuuid"); 
     502 
     503            $querystatement = "DELETE FROM reportsettings WHERE ".$linkedwhereclause.";"; 
     504            $queryresult = $this->db->query($querystatement); 
     505 
     506            $querystatement = "DELETE FROM reports WHERE ".$whereclause.";"; 
     507            $queryresult = $this->db->query($querystatement); 
     508 
     509            $message = $this->buildStatusMessage(); 
     510            $message.=" deleted."; 
     511            return $message; 
     512 
     513        }//end function delete_record 
     514 
     515    }//end class 
     516 
    134517}//end if 
    135518?> 
  • trunk/phpbms/modules/base/report/tabledefs_sqlexport.php

    r612 r693  
    3838*/ 
    3939 
    40         if(!isset($_SESSION["userinfo"])){ 
     40if(!class_exists("phpbmsReport")) 
     41    include("../../../report/report_class.php"); 
    4142 
    42                 session_cache_limiter('private'); 
     43class tabledefSQLExport extends phpbmsReport{ 
    4344 
    44                 require("../../../include/session.php"); 
     45    function tabledefSQLExport($db, $reportUUID, $tabledefUUID){ 
    4546 
    46         }//end if 
     47        parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     48 
     49    }//end method 
    4750 
    4851 
    49         if(!class_exists("phpbmsReport")) 
    50                 include("report/report_class.php"); 
     52    function generate(){ 
    5153 
    52         class tabledefSQLExport extends phpbmsReport{ 
     54            $this->reportOutput .= $this->_addTableInfo("tablecolumns"); 
     55            $this->reportOutput .= $this->_addTableInfo("tablefindoptions"); 
     56            $this->reportOutput .= $this->_addTableInfo("tablegroupings"); 
     57            $this->reportOutput .= $this->_addTableInfo("tableoptions"); 
     58            $this->reportOutput .= $this->_addTableInfo("tablesearchablefields"); 
    5359 
    54                 var $reportOutput = ""; 
    55  
    56                 function sqlExport($db){ 
    57  
    58                         parent::phpbmsReport($db); 
    59  
    60                 }//end method 
     60    }//end method 
    6161 
    6262 
    63                 function generate(){ 
     63    function _addTableInfo($tablename){ 
    6464 
    65                         $this->reportOutput .= $this->_addTableInfo("tablecolumns"); 
    66                         $this->reportOutput .= $this->_addTableInfo("tablefindoptions"); 
    67                         $this->reportOutput .= $this->_addTableInfo("tablegroupings"); 
    68                         $this->reportOutput .= $this->_addTableInfo("tableoptions"); 
    69                         $this->reportOutput .= $this->_addTableInfo("tablesearchablefields"); 
     65        $querystatement = " 
     66            SELECT 
     67                    `uuid` 
     68            FROM 
     69                    `tabledefs` 
     70            WHERE 
     71                    ".$this->whereClause; 
    7072 
    71                 }//end method 
     73        $queryresult = $this->db->query($querystatement); 
     74 
     75        $whereclause = ""; 
     76 
     77        while($therecord = $this->db->fetchArray($queryresult)) 
     78            $whereclause .= " OR `tabledefid` = '".mysql_real_escape_string($therecord["uuid"])."'"; 
     79 
     80        $whereclause = substr($whereclause, 4); 
     81 
     82        $output =       "/* Begin ".$tablename." */\n". 
     83                        "/* ====================================================================== */\n"; 
     84 
     85        $querystatement = " 
     86                SELECT 
     87                        * 
     88                FROM 
     89                        `".$tablename."` 
     90                WHERE 
     91                        ".$whereclause." 
     92                ORDER BY 
     93                        ".$tablename.".tabledefid"; 
     94 
     95        $queryresult = $this->db->query($querystatement); 
     96 
     97        $num_fields = $this->db->numFields($queryresult); 
     98 
     99        $statementstart = "INSERT INTO `".$tablename."` ("; 
     100 
     101        for($i=0; $i<$num_fields ;$i++){ 
     102 
     103            $fieldname = $this->db->fieldName($queryresult,$i); 
     104 
     105            if($fieldname != "id") 
     106                $statementstart .= "`".$fieldname."`, "; 
     107 
     108        }//endfor 
     109 
     110        $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES ("; 
     111 
     112        while($therecord = $this->db->fetchArray($queryresult)){ 
     113 
     114            $insertstatement = $statementstart; 
     115 
     116            foreach($therecord as $name => $field){ 
     117 
     118                if($field === NULL) 
     119                    $addfield = "NULL, "; 
     120                else 
     121                    $addfield = "'".mysql_real_escape_string($field)."', "; 
     122 
     123                if($name != "id") 
     124                    $insertstatement .= $addfield; 
     125 
     126            }//endforeach 
     127 
     128            $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n"; 
     129 
     130            $output .= $insertstatement; 
     131 
     132        }//endwhile 
    72133 
    73134 
    74                 function _addTableInfo($tablename){ 
     135        $output .=      "/* ====================================================================== */\n". 
     136                        "/* END ".$tablename." - record count: ".$this->db->numRows($queryresult)."*/\n\n"; 
    75137 
    76                         $querystatement = " 
    77                                 SELECT 
    78                                         `uuid` 
    79                                 FROM 
    80                                         `tabledefs` 
    81                                 WHERE 
    82                                         ".$this->whereclause." 
    83                                 "; 
     138        return $output; 
    84139 
    85                         $queryresult = $this->db->query($querystatement); 
    86  
    87                         $whereclause = ""; 
    88                         while($therecord = $this->db->fetchArray($queryresult)){ 
    89  
    90                                 $whereclause .= " OR `tabledefid` = '".mysql_real_escape_string($therecord["uuid"])."'"; 
    91  
    92                         }//end while 
    93  
    94                         $whereclause = substr($whereclause, 4); 
    95  
    96                         $output =       "/* Begin ".$tablename." */\n". 
    97                                                 "/* ====================================================================== */\n"; 
    98  
    99                         $querystatement = " 
    100                                 SELECT 
    101                                         * 
    102                                 FROM 
    103                                         `".$tablename."` 
    104                                 WHERE 
    105                                         ".$whereclause." 
    106                                 ORDER BY 
    107                                         ".$tablename.".tabledefid"; 
    108  
    109                         $queryresult = $this->db->query($querystatement); 
    110  
    111                         $num_fields = $this->db->numFields($queryresult); 
    112  
    113                         $statementstart = "INSERT INTO `".$tablename."` ("; 
    114  
    115                         for($i=0; $i<$num_fields ;$i++){ 
    116  
    117                                 $fieldname = $this->db->fieldName($queryresult,$i); 
    118  
    119                                 if($fieldname != "id") 
    120                                         $statementstart .= "`".$fieldname."`, "; 
    121  
    122                         }//endfor 
    123  
    124                         $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES ("; 
    125  
    126                         while($therecord = $this->db->fetchArray($queryresult)){ 
    127  
    128                                 $insertstatement = $statementstart; 
    129  
    130                                 foreach($therecord as $name => $field){ 
    131  
    132                                         if($field === NULL) 
    133                                                 $addfield = "NULL, "; 
    134                                         else 
    135                                                 $addfield = "'".mysql_real_escape_string($field)."', "; 
    136  
    137                                         if($name != "id") 
    138                                                 $insertstatement .= $addfield; 
    139  
    140                                 }//endforeach 
    141  
    142                                 $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n"; 
    143  
    144                                 $output .= $insertstatement; 
    145  
    146                         }//endwhile 
     140    }//end method 
    147141 
    148142 
    149                         $output .=      "/* ====================================================================== */\n". 
    150                                                 "/* END ".$tablename." - record count: ".$this->db->numRows($queryresult)."*/\n\n"; 
     143    function show(){ 
    151144 
    152                         return $output; 
     145        header("Content-type: text/plain"); 
     146        header('Content-Disposition: attachment; filename="tableInfoSQL.sql"'); 
    153147 
    154                 }//end method 
     148        echo $this->reportOutput; 
     149 
     150    }//end method 
    155151 
    156152 
    157                 function show(){ 
     153}//end class 
    158154 
    159                         header("Content-type: text/plain"); 
    160                         header('Content-Disposition: attachment; filename="tableInfoSQL.sql"'); 
     155/** 
     156 * PROCESSING 
     157 * ============================================================================= 
     158 */ 
     159if(!isset($noOutput)){ 
    161160 
    162                         echo $this->reportOutput; 
     161    session_cache_limiter('private'); 
    163162 
    164                 }//end method 
     163    require_once("../../../include/session.php"); 
    165164 
     165    checkForReportArguments(); 
    166166 
    167         }//end class 
     167    $report = new tabledefSQLExport($db, $_GET["rid"],$_GET["tid"]); 
     168    $report->setupFromPrintScreen(); 
     169    $report->generate(); 
     170    $report->show(); 
    168171 
    169         //PROCESSING 
    170         //======================================================================== 
     172}//end if 
    171173 
    172         if(!isset($noOutput)){ 
    173  
    174                 $report = new tabledefSQLExport($db); 
    175                 $report->setupFromPrintScreen(); 
    176                 $report->generate(); 
    177                 $report->show(); 
    178  
    179         }//end if 
     174/** 
     175 * When adding a new report record, the add/edit needs to know what the class 
     176 * name is so that it can instantiate it, and grab it's default settings. 
     177 */ 
     178if(isset($addingReportRecord)) 
     179    $reportClass ="tabledefSQLExport"; 
    180180?> 
  • trunk/phpbms/modules/base/reports_addedit.php

    r574 r693  
    4646        $therecord = $thetable->processAddEditPage(); 
    4747 
     48        if($therecord["id"]){ 
     49 
     50            $reportSettings = new reportSettings($db, $therecord["uuid"]); 
     51            $reportSettings->get(); 
     52 
     53        }//endif 
     54 
    4855        if(isset($therecord["phpbmsStatus"])) 
    4956                $statusmessage = $therecord["phpbmsStatus"]; 
     
    5158        $pageTitle="Report"; 
    5259 
    53         $phpbms->cssIncludes[] = "pages/reports.css"; 
     60        $phpbms->cssIncludes[] = "pages/base/reports.css"; 
     61        $phpbms->jsIncludes[] = "modules/base/javascript/reports.js"; 
    5462 
    5563                //Form Elements 
    5664                //============================================================== 
    57                 $theform = new phpbmsForm(); 
     65                $theform = new phpbmsForm(NULL, "post", "record", NULL); 
     66                $theform->id = "record"; 
    5867 
    5968                $theinput = new inputField("name",$therecord["name"],NULL,true,NULL,32,64); 
     
    7079                $theform->addField($theinput); 
    7180 
    72                 $theinput = new inputField("reportfile",$therecord["reportfile"],"report file",true,NULL,64,128); 
    73                 $theform->addField($theinput); 
     81                if($therecord["id"]){ 
     82 
     83                    $theinput = new inputField("reportfile",$therecord["reportfile"],"report file",true,NULL,64,128); 
     84                    $theinput->setAttribute("readonly","readonly"); 
     85                    $theinput->setAttribute("class","uneditable"); 
     86 
     87                    $theform->addField($theinput); 
     88 
     89                }//endif 
     90 
     91                $theinput = new inputTextarea("description", $therecord["description"], NULL, false, 3, 48); 
     92                $theform->addField($theinput); 
    7493 
    7594                $thetable->getCustomFieldInfo(); 
     
    82101 
    83102?><div class="bodyline"> 
    84         <?php $theform->startForm($pageTitle)?> 
    85  
     103<?php $theform->startForm($pageTitle) ?> 
    86104        <fieldset id="fsAttributes"> 
    87105                <legend>Attributes</legend> 
     106 
     107                <p><?php $theform->showField("type")?></p> 
    88108 
    89109                <p> 
    90110                        <label for="tabledefid">report table</label><br /> 
    91111                        <?php $thetable->displayTables("tabledefid",$therecord["tabledefid"]);?><br /> 
    92                         <span class="notes">Note: Use the global option to associate the report with every table in the system.</span> 
    93112                </p> 
    94113 
    95114                <p> 
    96115                        <?php $theform->showField("displayorder"); ?><br /> 
    97                         <span class="notes">Lower numbers are displayed first.  Reports with the same order are grouped together.</span> 
    98116                </p> 
    99117 
     
    108126                        <p class="big"><?php $theform->showField("name"); ?></p> 
    109127 
    110                         <p><?php $theform->showField("type")?></p> 
    111  
    112                         <p><?php $theform->showField("reportfile")?></p> 
    113128 
    114129                        <p> 
    115                                 <label for="description">description</label><br /> 
    116                                 <textarea id="description" name="description"  cols="61" rows="5" tabindex="35"><?php echo htmlQuotes($therecord["description"])?></textarea> 
    117                         </p> 
     130                        <?php 
     131                            if($therecord["id"]) 
     132                                $theform->showField("reportfile"); 
     133                            else 
     134                                $thetable->displayRerportFiles(); 
     135                        ?> 
     136                        </p> 
     137 
     138                        <p class="big"><?php $theform->showField("description"); ?></p> 
     139 
    118140                </fieldset> 
     141 
     142                <fieldset> 
     143                    <legend>settings</legend> 
     144                    <?php if(!$therecord["id"]) { 
     145                        ?><p class="notes">Report settings are available after initial record creation.</p><?php 
     146                    } else { 
     147                      ?> 
     148 
     149 
     150                        <textarea class="hiddenTextAreas" id="rsUpdates" name="rsUpdates" rows="1" cols="5"></textarea> 
     151                        <textarea class="hiddenTextAreas" id="rsDelList" name="rsDelList" rows="1" cols="5"></textarea> 
     152                        <textarea class="hiddenTextAreas" id="rsAdds"    name="rsAdds" rows="1" cols="5"></textarea> 
     153                        <table class="querytable simple" id="settingsTable" cellspacing="0" cellpadding="0" border="0" summary="report settings"> 
     154                            <thead> 
     155                                <tr> 
     156                                    <th align="right">name</th> 
     157                                    <th>value</th> 
     158                                    <th>type</th> 
     159                                    <th width="100%">description</th> 
     160                                    <th>&nbsp;</th> 
     161                                </tr> 
     162                            </thead> 
     163                            <tbody id="rsTbody"> 
     164                                <tr id="addNewRow"> 
     165                                    <td> 
     166                                        <input type="text" id="rsAddName"/> 
     167                                    </td> 
     168                                    <td> 
     169                                        <input type="text" id="rsAddValue" size="32"/> 
     170                                    </td> 
     171                                    <td>string</td> 
     172                                    <td>user added setting</td> 
     173                                    <td> 
     174                                        <button title="Add Setting" class="graphicButtons buttonPlus" id="rsButtonAdd" type="button"><span>+</span></button> 
     175                                    </td> 
     176                                </tr> 
     177                                <?php 
     178                                    $reportSettings->display(); 
     179                                ?> 
     180                                <tr class="queryfooter" id="rsFooterTr"> 
     181                                    <td colspan="5">&nbsp;</td> 
     182                                </tr> 
     183                            </tbody> 
     184                        </table> 
     185                      <?php 
     186                    }//endif 
     187                    ?> 
     188                </fieldset> 
    119189 
    120190                <?php $theform->showCustomFields($db, $thetable->customFieldsQueryResult) ?> 
     
    124194        <?php 
    125195                $theform->showGeneralInfo($phpbms,$therecord); 
    126                 $theform->endForm(); 
     196                $theform->endForm(); 
    127197        ?> 
    128198</div> 
  • trunk/phpbms/modules/bms/clients_purchasehistory.php

    r606 r693  
    5252        if(!isset($_POST["fromdate"])) $_POST["fromdate"]=dateToString(strtotime("-1 year")); 
    5353        if(!isset($_POST["todate"])) $_POST["todate"]=dateToString(mktime()); 
    54         if(!isset($_POST["status"])) $_POST["status"]="Orders/Invoices"; 
     54        if(!isset($_POST["status"])) $_POST["status"]="Orders and Invoices"; 
    5555        if(!isset($_POST["command"])) $_POST["command"]="show"; 
    5656 
    5757        if($_POST["command"]=="print")  { 
    5858 
    59                 $_SESSION["printing"]["whereclause"]="WHERE clients.id=".$_GET["id"]; 
    60                 $_SESSION["printing"]["dataprint"]="Single Record"; 
    61                 $fromClient=true; 
    62                 require("report/clients_purchasehistory.php"); 
     59            $_SESSION["printing"]["whereclause"] = "clients.id=".$_GET["id"]; 
     60            $_SESSION["printing"]["dataprint"] = "Single Record"; 
     61 
     62            goURL("report/clients_purchasehistory.php?rid=".urlencode("rpt:1908b03c-cacc-f03a-6d22-21fdef123f65")."&tid=".urlencode("tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083")."&status=".urlencode($_POST["status"])."&fromdate=".urlencode($_POST["fromdate"])."&todate=".urlencode($_POST["todate"])); 
    6363 
    6464        } else { 
     
    7272        $thestatus="(invoices.type =\""; 
    7373        switch($_POST["status"]){ 
    74                 case "Orders/Invoices": 
     74                case "Orders and Invoices": 
    7575                        $thestatus.="Order\" or invoices.type=\"Invoice\")"; 
    7676                break; 
     
    110110                thedate, 
    111111                invoices.id"; 
    112                  
     112 
    113113        $queryresult=$db->query($querystatement); 
    114114 
     
    142142                           <label for="status">type</label><br /> 
    143143                           <select name="status" id="status"> 
    144                                         <option value="Orders/Invoices" <?php if($_POST["status"]=="Orders/Invoices") echo "selected=\"selected\""?>>Orders/Invoices</option> 
     144                                        <option value="Orders abd Invoices" <?php if($_POST["status"]=="Orders and Invoices") echo "selected=\"selected\""?>>Orders and Invoices</option> 
    145145                                        <option value="Invoices" <?php if($_POST["status"]=="Invoices") echo "selected=\"selected\""?>>Invoices</option> 
    146146                                        <option value="Orders" <?php if($_POST["status"]=="Orders") echo "selected=\"selected\""?>>Orders</option> 
     
    153153 
    154154                        <p id="printP"><br /><input id="print" name="command" type="submit" value="print" class="Buttons" /></p> 
    155                         <p id="changeTimelineP"><br /><input name="command" type="submit" value="change timeframe/view" class="smallButtons" /></p> 
     155                        <p id="changeTimelineP"><br /><input name="command" type="submit" value="update" class="smallButtons" /></p> 
    156156                </div> 
    157157        </form> 
  • trunk/phpbms/modules/bms/install/install.php

    r496 r693  
    4747                        "relationships", 
    4848                        "reports", 
     49                        "reportsettings", 
    4950                        "tablecolumns", 
    5051                        "tabledefs", 
  • trunk/phpbms/modules/bms/install/reports.sql

    r643 r693  
    1 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:bac1d6eb-b2bb-9aa0-77c0-ff7f9046ca75', 'Invoice', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', '', 'modules/bms/report/invoices_pdfinvoice.php', 'This report will generate and display an invoice in PDF format (which can be printed or saved).  The PDF file will contain one page per invoice.', 1, NOW(), 1, NOW()); 
    2 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:a34dd4b5-6942-2b14-4a58-74345dce48de', 'Work Order', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'modules/bms/report/invoices_pdfworkorder.php', 'This report will generate and display a work order in PDF format (which can be printed or saved).  The PDF file will contain one page per work order.', 1, NOW(), 1, NOW()); 
    3 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:34a69580-6fbc-d04c-ed3e-f0e497a9a9b2', 'Packing List', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', '', 'modules/bms/report/invoices_pdfpackinglist.php', 'This report will generate and display an invoice packing list in PDF format (which can be printed or saved).  The PDF file will contain one page per invoice packing list.', 1, NOW(), 1, NOW()); 
    4 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:07f58303-d6e9-a032-01ad-0097d59b3c04', 'Labels - Folder', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', '', 'modules/bms/report/clients_folderlabels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
    5 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:030e7d95-4542-b37c-3cac-a18ff5f4b8ff', 'Labels - Mailing', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', '', 'modules/bms/report/clients_mailinglabels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
    6 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:c4a34fa0-16b5-dd85-cf63-5c8b543bb9c3', 'Labels - Shipping', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', '', 'modules/bms/report/clients_shippinglabels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
    7 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:a502aa38-4ae8-9aa7-2795-4a05a4814637', 'Labels - Shipping', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '60', '', 'modules/bms/report/invoices_shippinglabels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
    8 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:e3ef15d4-1bf5-36a1-cc05-ee44025ad619', 'Totals - Custom', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Creater your own custom invoice totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
    9 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:5ec9b1fb-f3c6-26c7-f1bc-bec4ac8448fd', 'Totals - Amt. w/  Invoices', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_amtwinv.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields  and displaying indidivdual invoice information.', 1, NOW(), 1, NOW()); 
    10 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:960ec744-4955-81d1-8170-e56251603e4b', 'Totals - Amt. w/ Invoices + Line Items', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_amtwinvlineitems.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields  and displaying indidivdual invoice and line item information.', 1, NOW(), 1, NOW()); 
    11 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:47407854-cb7f-f1e3-bc44-1b3979eae9b0', 'Totals - Grouped by Acct. Manager', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_acctmngers.php', 'Totals report grouping by client account manager', 1, NOW(), 1, NOW()); 
    12 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:05de9afc-c82c-ed66-9403-184aa3f07a1c', 'Totals - Grouped by Shipping Method', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_shippingmethod.php', 'Totals report including shipping ammount grouped by shipping method', 1, NOW(), 1, NOW()); 
    13 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:60c71b67-5cf1-6d1b-6d96-a4dfe9bbd651', 'Totals - Grouped by Payment Method', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_payment.php', 'Totals report grouped by payment method.', 1, NOW(), 1, NOW()); 
    14 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:7a7672ef-f11c-9a6a-5640-708c50cadd29', 'Totals - Grouped by Invoice Lead Source', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_leadsource.php', 'Totals - Grouped by invoice lead source', 1, NOW(), 1, NOW()); 
    15 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:49c0907c-9253-4fcb-0717-37952dd0ef4e', 'Quote', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'modules/bms/report/invoices_pdfquote.php', 'PDF report for quote.  Does not include amount due.', 1, NOW(), 1, NOW()); 
    16 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:a278af28-9c34-da2e-d81b-4caa36dfa29f', 'Sales History', 'report', 'tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34', '100', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/products_saleshistory.php', 'Sales History for product including costs, average price and quantities.', 1, NOW(), 1, NOW()); 
    17 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:1908b03c-cacc-f03a-6d22-21fdef123f65', 'Purchase History', 'report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '10', '', 'modules/bms/report/clients_purchasehistory.php', 'Client purchase history', 1, NOW(), 1, NOW()); 
    18 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:858702da-1b85-3a62-c20f-6b1593140a64', 'Totals - Custom', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Create your own custom line item  totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
    19 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:28cf69cb-60de-bbed-df15-ea98842b6924', 'Totals - Product Categories', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals_productcategories.php', 'Totals report grouped first by product category and then by product.', 1, NOW(), 1, NOW()); 
    20 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:274d3dfa-ec52-74d2-630f-0c432a6e1ea5', 'Totals - Product', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals_products.php', 'Totals report grouped by product displaying line items', 1, NOW(), 1, NOW()); 
    21 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:68b6258a-6902-f705-19f5-d2707bd78b35', 'Totals - Lead Source', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals_leadsource.php', 'Totals grouped by invoice lead source and product', 1, NOW(), 1, NOW()); 
    22 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:b552c34f-64b9-5a89-15b3-c5d717644b81', 'Client Notes Summary', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '10', '', 'modules/bms/report/clients_notesummary.php', 'Print all notes associated with the client and any notes associated with client invoices.', 1, NOW(), 1, NOW()); 
    23 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:aca42dbe-68c9-e966-c174-ed938e9b880a', 'Totals - Tax', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals_tax.php', 'Tax Totals', 1, NOW(), 1, NOW()); 
    24 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:e54cee32-b3c9-82cc-50c8-14848ece8e90', 'Receipt', 'PDF Report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pdf.php', 'PDF print out of receipt for processing or client records', 1, NOW(), 1, NOW()); 
    25 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:0df82ecf-5f05-56bd-18c3-e7cb27c0cf8a', 'Client Statements', 'PDF Report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_clientstatement.php', 'Client AR statement balances and activity.', 1, NOW(), 1, NOW()); 
    26 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:e25bdb7a-93be-b1d6-a292-cdec89c0c9fc', 'Summary', 'report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_summary.php', 'Items grouped and totaled by clients, with grand totals.', 1, NOW(), 1, NOW()); 
    27 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:916f34d8-0997-162c-4350-d93c3d283241', 'Payment Type Totals', 'report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pttotals.php', 'Totals grouped by payment method.', 1, NOW(), 1, NOW()); 
    28 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:4851c350-4343-4dc3-4b7b-74c287de011b', 'Incoming Cash Flow', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '55', 'role:8f5fb368-e7d9-5010-d8f6-b4a78adc0520', 'modules/bms/report/incoming_cashflow.php', 'This report shows total incoming monies for a time period from both posted sales orders AND posted receipts. It can be grouped by week, month, quarter and year.\r\n\r\nThis report runs is unaffected by selected records, search or sort parameters.  It requires input of its own start and end dates.', 1, NOW(), 1, NOW()); 
     1INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('207', 'rpt:e3ef15d4-1bf5-36a1-cc05-ee44025ad619', 'Totals - Custom', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Creater your own custom invoice totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
     2INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('215', 'rpt:a278af28-9c34-da2e-d81b-4caa36dfa29f', 'Sales History', 'report', 'tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34', '100', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/products_saleshistory.php', 'Sales History for product including costs, average price and quantities.', 1, NOW(), 1, NOW()); 
     3INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('216', 'rpt:1908b03c-cacc-f03a-6d22-21fdef123f65', 'Purchase History', 'report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '10', '', 'modules/bms/report/clients_purchasehistory.php', 'Client purchase history', 1, NOW(), 1, NOW()); 
     4INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('217', 'rpt:858702da-1b85-3a62-c20f-6b1593140a64', 'Totals - Custom', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Creat your own custom line item  totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
     5INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('224', 'rpt:0df82ecf-5f05-56bd-18c3-e7cb27c0cf8a', 'Client Statements', 'PDF Report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_clientstatement.php', 'Client AR statement balances and activity.', 1, NOW(), 1, NOW()); 
     6INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('225', 'rpt:e25bdb7a-93be-b1d6-a292-cdec89c0c9fc', 'Summary', 'report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_summary.php', 'Items grouped and totaled by clients, with grand totals.', 1, NOW(), 1, NOW()); 
     7INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('226', 'rpt:916f34d8-0997-162c-4350-d93c3d283241', 'Payment Type Totals', 'report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pttotals.php', 'Totals grouped by payment method.', 1, NOW(), 1, NOW()); 
     8INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('227', 'rpt:4851c350-4343-4dc3-4b7b-74c287de011b', 'Incoming Cash Flow', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '55', 'role:8f5fb368-e7d9-5010-d8f6-b4a78adc0520', 'modules/bms/report/incoming_cashflow.php', 'This report shows total incoming monies for a time period from both posted sales orders AND posted receipts. It can be grouped by week, month, quarter and year.\r\n\r\nThis report runs is unaffected by selected records, search or sort parameters.  It requires input of its own start and end dates.', 1, NOW(), 1, NOW()); 
     9INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('233', 'reports:e3057c38-0f68-5d1d-a1b7-793183d951d2', 'Labels - Folder', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     10INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('234', 'rpt:1019eae2-50d4-e097-c73c-3748c2bd7840', 'Labels - Mailing', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     11INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('235', 'rpt:805fe2c4-a0d2-185a-5609-a444da07d61a', 'Labels - Shipping', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     12INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('236', 'rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f', 'Labels - Shipping', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '60', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     13INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('240', 'rpt:435d3c34-0ca3-5d40-3488-e5593869c20c', 'Totals - Lead Source', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals grouped by invoice lead source and product', 1, NOW(), 1, NOW()); 
     14INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('241', 'rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39', 'Totals - Products', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals report grouped by product displaying line items', 1, NOW(), 1, NOW()); 
     15INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('242', 'rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c', 'Totals - Product Categories', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals report grouped first by product category and then by product.', 1, NOW(), 1, NOW()); 
     16INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('243', 'rpt:b934c506-ee84-f260-283b-9cb07050b197', 'Receipt', 'PDF Report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pdf.php', 'PDF print out of receipt for processing or client records', 1, NOW(), 1, NOW()); 
     17INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('244', 'rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a', 'Totals - Account Manager', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report grouping by client account manager', 1, NOW(), 1, NOW()); 
     18INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('246', 'rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b', 'Totals - Amount with Invoices', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields and displaying individual invoice information.', 1, NOW(), 1, NOW()); 
     19INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('247', 'rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348', 'Totals - Amounts with Invoices and Line Items', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields and displaying individual invoice and line item information.', 1, NOW(), 1, NOW()); 
     20INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('248', 'rpt:3cb9ae81-0838-863e-0185-1f46224cbe00', 'Totals - Sales Order Lead Source', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals - Grouped by invoice lead source', 1, NOW(), 1, NOW()); 
     21INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('249', 'rpt:67dca680-14ba-d4e7-4926-b90c65495f48', 'Totals - Pament Methods', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report grouped by payment method.', 1, NOW(), 1, NOW()); 
     22INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('250', 'rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140', 'Totals - Shipping Methods', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report including shipping amount grouped by shipping method', 1, NOW(), 1, NOW()); 
     23INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('251', 'rpt:d97334ef-0139-f178-fe36-c38e151cc60e', 'Totals - Tax', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Sales order tax totals', 1, NOW(), 1, NOW()); 
     24INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('256', 'rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b', 'Invoice', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfinvoice.php', 'Printable/E-Mail Ready Invoice PDF', 1, NOW(), 1, NOW()); 
     25INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('257', 'rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73', 'Packing List', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfpackinglist.php', 'Packing (pick) List PDF', 1, NOW(), 1, NOW()); 
     26INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('258', 'rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca', 'Quote', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfquote.php', 'Quote PDF.  Does not include amount due.', 1, NOW(), 1, NOW()); 
     27INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('259', 'rpt:30a56a65-8673-b3c0-cd50-6546968b4d37', 'Work Order', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'modules/bms/report/invoices_pdfworkorder.php', 'Work Order PDF', 1, NOW(), 1, NOW()); 
  • trunk/phpbms/modules/bms/install/updatev0.98.sql

    r682 r693  
    336336INSERT INTO `relationships` (`uuid`, `tofield`, `name`, `fromfield`, `fromtableid`, `totableid`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`, `inherint`) VALUES ('rln:c003c109-b79b-eded-9acd-b251af8d92ec', 'postingsessionid', 'receipts', 'id', 'tbld:97760a4f-1c1a-a108-d05f-5fc4ec59583c', 'tbld:43678406-be25-909b-c715-7e2afc7db601', 1, NOW(), 1, NOW(), '0'); 
    337337--end relationships INSERT-- 
    338 --reports INSERT-- 
    339 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:0df82ecf-5f05-56bd-18c3-e7cb27c0cf8a', 'Client Statements', 'PDF Report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_clientstatement.php', 'Client AR statement balances and activity.', 1, NOW(), 1, NOW()); 
    340 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:e25bdb7a-93be-b1d6-a292-cdec89c0c9fc', 'Summary', 'report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_summary.php', 'Items grouped and totaled by clients, with grand totals.', 1, NOW(), 1, NOW()); 
    341 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:916f34d8-0997-162c-4350-d93c3d283241', 'Payment Type Totals', 'report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pttotals.php', 'Totals grouped by payment method.', 1, NOW(), 1, NOW()); 
    342 INSERT INTO `reports` (`uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('rpt:4851c350-4343-4dc3-4b7b-74c287de011b', 'Incoming Cash Flow', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '55', 'role:8f5fb368-e7d9-5010-d8f6-b4a78adc0520', 'modules/bms/report/incoming_cashflow.php', 'This report shows total incoming monies for a time period from both posted sales orders AND posted receipts. It can be grouped by week, month, quarter and year.\r\n\r\nThis report runs is unaffected by selected records, search or sort parameters.  It requires input of its own start and end dates.', 1, NOW(), 1, NOW()); 
    343 --end reports INSERT-- 
    344 --reports UPDATE-- 
    345 UPDATE `reports` SET `uuid`='rpt:bac1d6eb-b2bb-9aa0-77c0-ff7f9046ca75' WHERE `name`='Invoice'; 
    346 UPDATE `reports` SET `uuid`='rpt:a34dd4b5-6942-2b14-4a58-74345dce48de' WHERE `name`='Work Order'; 
    347 UPDATE `reports` SET `uuid`='rpt:34a69580-6fbc-d04c-ed3e-f0e497a9a9b2' WHERE `name`='Packing List'; 
    348 UPDATE `reports` SET `uuid`='rpt:07f58303-d6e9-a032-01ad-0097d59b3c04' WHERE `name`='Labels - Folder'; 
    349 UPDATE `reports` SET `uuid`='rpt:030e7d95-4542-b37c-3cac-a18ff5f4b8ff' WHERE `name`='Labels - Mailing'; 
    350 UPDATE `reports` SET `uuid`='rpt:c4a34fa0-16b5-dd85-cf63-5c8b543bb9c3' WHERE `name`='Labels - Shipping' AND `tabledefid`='2'; 
    351 UPDATE `reports` SET `uuid`='rpt:a502aa38-4ae8-9aa7-2795-4a05a4814637' WHERE `name`='Labels - Shipping' AND `tabledefid`='3'; 
    352 UPDATE `reports` SET `uuid`='rpt:e3ef15d4-1bf5-36a1-cc05-ee44025ad619' WHERE `name`='Totals - Custom' AND `tabledefid`='3'; 
    353 UPDATE `reports` SET `uuid`='rpt:5ec9b1fb-f3c6-26c7-f1bc-bec4ac8448fd' WHERE `name`='Totals - Amt. w/  Invoices'; 
    354 UPDATE `reports` SET `uuid`='rpt:960ec744-4955-81d1-8170-e56251603e4b' WHERE `name`='Totals - Amt. w/ Invoices + Line Items'; 
    355 UPDATE `reports` SET `uuid`='rpt:47407854-cb7f-f1e3-bc44-1b3979eae9b0' WHERE `name`='Totals - Grouped by Acct. Manager'; 
    356 UPDATE `reports` SET `uuid`='rpt:05de9afc-c82c-ed66-9403-184aa3f07a1c' WHERE `name`='Totals - Grouped by Shipping Method'; 
    357 UPDATE `reports` SET `uuid`='rpt:60c71b67-5cf1-6d1b-6d96-a4dfe9bbd651' WHERE `name`='Totals - Grouped by Payment Method'; 
    358 UPDATE `reports` SET `uuid`='rpt:7a7672ef-f11c-9a6a-5640-708c50cadd29' WHERE `name`='Totals - Grouped by Invoice Lead Source'; 
    359 UPDATE `reports` SET `uuid`='rpt:49c0907c-9253-4fcb-0717-37952dd0ef4e' WHERE `name`='Quote'; 
    360 UPDATE `reports` SET `uuid`='rpt:a278af28-9c34-da2e-d81b-4caa36dfa29f' WHERE `name`='Sales History'; 
    361 UPDATE `reports` SET `uuid`='rpt:1908b03c-cacc-f03a-6d22-21fdef123f65' WHERE `name`='Purchase History'; 
    362 UPDATE `reports` SET `uuid`='rpt:858702da-1b85-3a62-c20f-6b1593140a64' WHERE `name`='Totals - Custom' AND `tabledefid`='5'; 
    363 UPDATE `reports` SET `uuid`='rpt:28cf69cb-60de-bbed-df15-ea98842b6924' WHERE `name`='Totals - Product Categories'; 
    364 UPDATE `reports` SET `uuid`='rpt:274d3dfa-ec52-74d2-630f-0c432a6e1ea5' WHERE `name`='Totals - Product'; 
    365 UPDATE `reports` SET `uuid`='rpt:68b6258a-6902-f705-19f5-d2707bd78b35' WHERE `name`='Totals - Lead Source'; 
    366 UPDATE `reports` SET `uuid`='rpt:b552c34f-64b9-5a89-15b3-c5d717644b81' WHERE `name`='Client Notes Summary'; 
    367 UPDATE `reports` SET `uuid`='rpt:aca42dbe-68c9-e966-c174-ed938e9b880a' WHERE `name`='Totals - Tax'; 
    368 UPDATE `reports` SET `uuid`='rpt:e54cee32-b3c9-82cc-50c8-14848ece8e90' WHERE `name`='Receipt'; 
    369 --end reports UPDATE-- 
     338--reports DELETE/INSERT-- 
     339DELETE FROM `reports` WHERE `name` IN ('Receipt', 'Totals - Tax', 'report', 'Client Notes Summary', 'Totals - Lead Source', 'Totals - Product', 'Totals - Product Categories', 'Totals - Custom', 'Purchase History', 'Sales History', 'Quote', 'Totals - Grouped by Invoice Lead Source', 'Totals - Grouped by Payment Method', 'Totals - Grouped by Shipping Method', 'Totals - Grouped by Acct. Manager', 'Totals - Amt. w/ Invoices + Line Items', 'Totals - Amt. w/  Invoices', 'Labels - Shipping', 'Labels - Mailing', 'Labels - Folder', 'Packing List', 'Work Order', 'Invoice') 
     340INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('207', 'rpt:e3ef15d4-1bf5-36a1-cc05-ee44025ad619', 'Totals - Custom', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Creater your own custom invoice totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
     341INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('215', 'rpt:a278af28-9c34-da2e-d81b-4caa36dfa29f', 'Sales History', 'report', 'tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34', '100', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/products_saleshistory.php', 'Sales History for product including costs, average price and quantities.', 1, NOW(), 1, NOW()); 
     342INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('216', 'rpt:1908b03c-cacc-f03a-6d22-21fdef123f65', 'Purchase History', 'report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '10', '', 'modules/bms/report/clients_purchasehistory.php', 'Client purchase history', 1, NOW(), 1, NOW()); 
     343INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('217', 'rpt:858702da-1b85-3a62-c20f-6b1593140a64', 'Totals - Custom', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Creat your own custom line item  totaling report, specify groupings, totals, averages and whether to display summary, invoice, and invoice detail information.', 1, NOW(), 1, NOW()); 
     344INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('224', 'rpt:0df82ecf-5f05-56bd-18c3-e7cb27c0cf8a', 'Client Statements', 'PDF Report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_clientstatement.php', 'Client AR statement balances and activity.', 1, NOW(), 1, NOW()); 
     345INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('225', 'rpt:e25bdb7a-93be-b1d6-a292-cdec89c0c9fc', 'Summary', 'report', 'tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/aritems_summary.php', 'Items grouped and totaled by clients, with grand totals.', 1, NOW(), 1, NOW()); 
     346INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('226', 'rpt:916f34d8-0997-162c-4350-d93c3d283241', 'Payment Type Totals', 'report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pttotals.php', 'Totals grouped by payment method.', 1, NOW(), 1, NOW()); 
     347INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('227', 'rpt:4851c350-4343-4dc3-4b7b-74c287de011b', 'Incoming Cash Flow', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '55', 'role:8f5fb368-e7d9-5010-d8f6-b4a78adc0520', 'modules/bms/report/incoming_cashflow.php', 'This report shows total incoming monies for a time period from both posted sales orders AND posted receipts. It can be grouped by week, month, quarter and year.\r\n\r\nThis report runs is unaffected by selected records, search or sort parameters.  It requires input of its own start and end dates.', 1, NOW(), 1, NOW()); 
     348INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('233', 'reports:e3057c38-0f68-5d1d-a1b7-793183d951d2', 'Labels - Folder', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     349INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('234', 'rpt:1019eae2-50d4-e097-c73c-3748c2bd7840', 'Labels - Mailing', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     350INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('235', 'rpt:805fe2c4-a0d2-185a-5609-a444da07d61a', 'Labels - Shipping', 'PDF Report', 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083', '50', NULL, 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     351INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('236', 'rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f', 'Labels - Shipping', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '60', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'report/general_labels.php', 'Avery 5160 or compatible (3x10) Instructor Folder labels. \r\n\r\n **MAKE SURE when printing the pdf file, to TURN OFF the option \"shrink oversized pages to paper size\".**', 1, NOW(), 1, NOW()); 
     352INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('240', 'rpt:435d3c34-0ca3-5d40-3488-e5593869c20c', 'Totals - Lead Source', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals grouped by invoice lead source and product', 1, NOW(), 1, NOW()); 
     353INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('241', 'rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39', 'Totals - Products', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals report grouped by product displaying line items', 1, NOW(), 1, NOW()); 
     354INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('242', 'rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c', 'Totals - Product Categories', 'report', 'tbld:31423480-a9b0-f0ff-749e-b3b5e18ca93c', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/lineitems_totals.php', 'Totals report grouped first by product category and then by product.', 1, NOW(), 1, NOW()); 
     355INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('243', 'rpt:b934c506-ee84-f260-283b-9cb07050b197', 'Receipt', 'PDF Report', 'tbld:43678406-be25-909b-c715-7e2afc7db601', '10', 'role:c9439c3c-499b-7bcc-ee14-fec5bfcf5fc2', 'modules/bms/report/receipts_pdf.php', 'PDF print out of receipt for processing or client records', 1, NOW(), 1, NOW()); 
     356INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('244', 'rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a', 'Totals - Account Manager', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report grouping by client account manager', 1, NOW(), 1, NOW()); 
     357INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('246', 'rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b', 'Totals - Amount with Invoices', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields and displaying individual invoice information.', 1, NOW(), 1, NOW()); 
     358INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('247', 'rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348', 'Totals - Amounts with Invoices and Line Items', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Basic totals report. Shows invoice total, subtotal and amount due fields and displaying individual invoice and line item information.', 1, NOW(), 1, NOW()); 
     359INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('248', 'rpt:3cb9ae81-0838-863e-0185-1f46224cbe00', 'Totals - Sales Order Lead Source', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals - Grouped by invoice lead source', 1, NOW(), 1, NOW()); 
     360INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('249', 'rpt:67dca680-14ba-d4e7-4926-b90c65495f48', 'Totals - Pament Methods', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report grouped by payment method.', 1, NOW(), 1, NOW()); 
     361INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('250', 'rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140', 'Totals - Shipping Methods', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Totals report including shipping amount grouped by shipping method', 1, NOW(), 1, NOW()); 
     362INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('251', 'rpt:d97334ef-0139-f178-fe36-c38e151cc60e', 'Totals - Tax', 'report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '50', 'role:259ead9f-100b-55b5-508a-27e33a6216bf', 'modules/bms/report/invoices_totals.php', 'Sales order tax totals', 1, NOW(), 1, NOW()); 
     363INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('256', 'rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b', 'Invoice', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfinvoice.php', 'Printable/E-Mail Ready Invoice PDF', 1, NOW(), 1, NOW()); 
     364INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('257', 'rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73', 'Packing List', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfpackinglist.php', 'Packing (pick) List PDF', 1, NOW(), 1, NOW()); 
     365INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('258', 'rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca', 'Quote', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', NULL, 'modules/bms/report/invoices_pdfquote.php', 'Quote PDF.  Does not include amount due.', 1, NOW(), 1, NOW()); 
     366INSERT INTO `reports` (`id`, `uuid`, `name`, `type`, `tabledefid`, `displayorder`, `roleid`, `reportfile`, `description`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`) VALUES ('259', 'rpt:30a56a65-8673-b3c0-cd50-6546968b4d37', 'Work Order', 'PDF Report', 'tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883', '100', 'role:de7e6679-8bb2-29ee-4883-2fcd756fb120', 'modules/bms/report/invoices_pdfworkorder.php', 'Work Order PDF', 1, NOW(), 1, NOW()); 
     367--end reports DELETE/INSERT-- 
     368--reportsettings INSERT-- 
     369INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','maxRows','10','int',1,'10','Number of label rows per page'); 
     370INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','maxColumns','3','int',1,'3','Number of label columns per page'); 
     371INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','startTop','0.5','real',1,'0.5','Top Margin of page'); 
     372INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','startLeft','0.1875','real',1,'0.1875','Left Margin of page'); 
     373INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','columnMargin','0.125','real',1,'0.125','Distance between columns'); 
     374INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','labelHeight','1','real',1,'1','Height of a single label'); 
     375INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','labelHeight','2.625','real',1,'2.625','Width of a single label'); 
     376INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','labelMarginLeft','0.0625','real',1,'0.0625','Distance from left between the start of an individual to the text being put on it'); 
     377INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','labelMarginTop','0.125','real',1,'0.125','Distance from top between start of an individual to the text being put on it'); 
     378INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','queryStatement','SELECT if(clients.lastname != \'\' || clients.lastname is not null, concat(clients.lastname, \', \', clients.firstname), \'\') as rowText1, clients.company as rowText2, concat(addresses.city, \', \', addresses.state) as rowText3 FROM ((clients INNER JOIN addresstorecord on clients.uuid = addresstorecord.recordid AND addresstorecord.tabledefid=\'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083\' AND addresstorecord.primary=1) INNER JOIN addresses ON  addresstorecord.addressid = addresses.uuid)','text',1,'SELECT \"no data in first row\" AS `rowText1`,  \"no data in second row\" AS `rowText2` FROM `reports`','SQL SELECT and FROM clauses defining the data to be retrieved.  Each line printed should be selected as a column in the format `rowText(X)`, where (X) is the line number it will be printed on'); 
     379INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','rowText1Font','Arial,B,9','string',0,'Arial,B,9','Comma separated list of FPF parameters defining font settings for the label text.  You can change the font on subsequent lines by adding an additional setting rowText(x)Font where (x) is the line number the font change occurs.'); 
     380INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:e3057c38-0f68-5d1d-a1b7-793183d951d2','rowText3Font','Arial,,8','string',0,'',NULL); 
     381INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','maxRows','10','int',1,'10','Number of label rows per page'); 
     382INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','maxColumns','3','int',1,'3','Number of label columns per page'); 
     383INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','startTop','0.5','real',1,'0.5','Top Margin of page'); 
     384INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','startLeft','0.1875','real',1,'0.1875','Left Margin of page'); 
     385INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','columnMargin','0.125','real',1,'0.125','Distance between columns'); 
     386INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','labelHeight','1','real',1,'1','Height of a single label'); 
     387INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','labelHeight','2.625','real',1,'2.625','Width of a single label'); 
     388INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','labelMarginLeft','0.0625','real',1,'0.0625','Distance from left between the start of an individual to the text being put on it'); 
     389INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','labelMarginTop','0.125','real',1,'0.125','Distance from top between start of an individual to the text being put on it'); 
     390INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','queryStatement','SELECT clients.company AS rowText1, trim(concat(clients.firstname, \' \', clients.lastname)) AS rowText2, addresses.address1 AS rowText3, addresses.address2 AS rowText4, concat(addresses.city, \', \', addresses.state, \' \', addresses.postalcode) AS rowText5, addresses.country AS rowText6 FROM ((clients INNER JOIN addresstorecord on clients.uuid = addresstorecord.recordid AND addresstorecord.tabledefid=\'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083\' AND addresstorecord.primary=1) INNER JOIN addresses ON  addresstorecord.addressid = addresses.uuid)','text',1,'SELECT \"no data in first row\" AS `rowText1`,  \"no data in second row\" AS `rowText2` FROM `reports`','SQL SELECT and FROM clauses defining the data to be retrieved.  Each line printed should be selected as a column in the format `rowText(X)`, where (X) is the line number it will be printed on'); 
     391INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','rowText1Font','Arial,B,9','string',0,'Arial,B,9','Comma separated list of FPDF font parameters defining font settings for the label text.  You can change the font on subsequent lines by adding an additional setting rowText(x)Font where (x) is the line number the font change occurs.'); 
     392INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:1019eae2-50d4-e097-c73c-3748c2bd7840','rowText3Font','Arial,,8','string',0,'',NULL); 
     393INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','maxRows','10','int',1,'10','Number of label rows per page'); 
     394INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','maxColumns','3','int',1,'3','Number of label columns per page'); 
     395INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','startTop','0.5','real',1,'0.5','Top Margin of page'); 
     396INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','startLeft','0.1875','real',1,'0.1875','Left Margin of page'); 
     397INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','columnMargin','0.125','real',1,'0.125','Distance between columns'); 
     398INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','labelHeight','1','real',1,'1','Height of a single label'); 
     399INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','labelHeight','2.625','real',1,'2.625','Width of a single label'); 
     400INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','labelMarginLeft','0.0625','real',1,'0.0625','Distance from left between the start of an individual to the text being put on it'); 
     401INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','labelMarginTop','0.125','real',1,'0.125','Distance from top between start of an individual to the text being put on it'); 
     402INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','queryStatement','SELECT clients.company AS rowText1, if(shiptoname != \'\' && shiptoname is not null, trim(shiptoname), trim(concat(clients.firstname, \' \', clients.lastname))) AS rowText2, addresses.address1 AS rowText3, addresses.address2 AS rowText4, concat(addresses.city, \', \', addresses.state, \' \', addresses.postalcode) AS rowText5, addresses.country AS rowText6 FROM ((clients INNER JOIN addresstorecord on clients.uuid = addresstorecord.recordid AND addresstorecord.tabledefid=\'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083\' AND addresstorecord.defaultshipto=1) INNER JOIN addresses ON  addresstorecord.addressid = addresses.uuid)','text',1,'SELECT \"no data in first row\" AS `rowText1`,  \"no data in second row\" AS `rowText2` FROM `reports`','SQL SELECT and FROM clauses defining the data to be retrieved.  Each line printed should be selected as a column in the format `rowText(X)`, where (X) is the line number it will be printed on'); 
     403INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','rowText1Font','Arial,B,9','string',0,'Arial,B,9','Comma separated list of FPDF font parameters defining font settings for the label text.  You can change the font on subsequent lines by adding an additional setting rowText(x)Font where (x) is the line number the font change occurs.'); 
     404INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:805fe2c4-a0d2-185a-5609-a444da07d61a','rowText3Font','Arial,,8','string',0,'',NULL); 
     405INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','maxRows','10','int',1,'10','Number of label rows per page'); 
     406INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','maxColumns','3','int',1,'3','Number of label columns per page'); 
     407INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','startTop','0.5','real',1,'0.5','Top Margin of page'); 
     408INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','startLeft','0.1875','real',1,'0.1875','Left Margin of page'); 
     409INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','columnMargin','0.125','real',1,'0.125','Distance between columns'); 
     410INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','labelHeight','1','real',1,'1','Height of a single label'); 
     411INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','labelHeight','2.625','real',1,'2.625','Width of a single label'); 
     412INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','labelMarginLeft','0.0625','real',1,'0.0625','Distance from left between the start of an individual to the text being put on it'); 
     413INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','labelMarginTop','0.125','real',1,'0.125','Distance from top between start of an individual to the text being put on it'); 
     414INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','queryStatement','SELECT clients.company AS rowText1, if(shiptosameasbilling = 0 && shiptoname != \'\' && shiptoname IS NOT NULL, shiptoname, trim(concat(clients.firstname, \' \', clients.lastname))) AS rowText2, if(shiptosameasbilling = 0, shiptoaddress1, invoices.address1) AS rowText3, if(shiptosameasbilling = 0, shiptoaddress2, invoices.address2) AS rowText4, if(shiptosameasbilling = 0, concat(shiptocity, \', \',shiptostate,\' \',shiptopostalcode), concat(invoices.city,\', \',invoices.state,\' \',invoices.postalcode)) AS rowText5, if(shiptosameasbilling = 0, shiptocountry, invoices.country) AS rowText6 FROM invoices INNER JOIN clients ON invoices.clientid=clients.uuid','text',1,'SELECT \"no data in first row\" AS `rowText1`,  \"no data in second row\" AS `rowText2` FROM `reports`','SQL SELECT and FROM clauses defining the data to be retrieved.  Each line printed should be selected as a column in the format `rowText(X)`, where (X) is the line number it will be printed on'); 
     415INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','rowText1Font','Arial,B,9','string',0,'Arial,B,9','Comma separated list of FPDF font parameters defining font settings for the label text.  You can change the font on subsequent lines by adding an additional setting rowText(x)Font where (x) is the line number the font change occurs.'); 
     416INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:7d461e1a-1bf3-b484-6b58-bf99126ad95f','rowText3Font','Arial,,8','string',0,'',NULL); 
     417INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','reportTitle','Totals Grouped by Invoice Lead Source and Product','string',0,'Report','Report Title'); 
     418INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','column1','1','string',0,'',NULL); 
     419INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','column2','4','string',0,'',NULL); 
     420INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','column4','8','string',0,'',NULL); 
     421INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','column5','5','string',0,'',NULL); 
     422INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','group1','14','string',0,'',NULL); 
     423INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','group2','1','string',0,'',NULL); 
     424INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','showWhat','totals','string',0,'',NULL); 
     425INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:435d3c34-0ca3-5d40-3488-e5593869c20c','column3','9','string',0,'',NULL); 
     426INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','reportTitle','Totals Grouped by Product','string',0,'Report','Report Title'); 
     427INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','column1','1','string',0,'',NULL); 
     428INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','column2','4','string',0,'',NULL); 
     429INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','column3','9','string',0,'',NULL); 
     430INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','column4','8','string',0,'',NULL); 
     431INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','column5','5','string',0,'',NULL); 
     432INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','group1','1','string',0,'',NULL); 
     433INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:157ec22d-14c2-64cc-486a-fedc9cfe7d39','showWhat','lineitems','string',0,'',NULL); 
     434INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','reportTitle','Totals Grouped by Product Categories and Product','string',0,'Report','Report Title'); 
     435INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','column1','1','string',0,'',NULL); 
     436INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','column2','4','string',0,'',NULL); 
     437INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','column3','9','string',0,'',NULL); 
     438INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','column4','8','string',0,'',NULL); 
     439INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','column5','5','string',0,'',NULL); 
     440INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','group1','2','string',0,'',NULL); 
     441INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','group2','1','string',0,'',NULL); 
     442INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b2402d8d-10e3-30b2-2c92-e6da9bd0093c','showWhat','totals','string',0,'',NULL); 
     443INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b934c506-ee84-f260-283b-9cb07050b197','reportTitle','Receipt','string',1,'Receipts','Title printed in upper right hand of report.'); 
     444INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','reportTitle','Totals Grouped by Client Account Manager','string',0,'Report','Report Title'); 
     445INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','showWhat','invoices','string',0,'',NULL); 
     446INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','column1','11','string',0,'',NULL); 
     447INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','column2','1','string',0,'',NULL); 
     448INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','column3','3','string',0,'',NULL); 
     449INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','group1','13','string',0,'',NULL); 
     450INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5ff03ba4-a310-524e-f3a3-05b6cadf820a','group2','12','string',0,'',NULL); 
     451INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b','reportTitle','Subtotals, Totals, and Amount Due','string',0,'Report','Report Title'); 
     452INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b','showWhat','invoices','string',0,'',NULL); 
     453INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b','column1','11','string',0,'',NULL); 
     454INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b','column2','1','string',0,'',NULL); 
     455INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3e25c485-857d-1698-6c9b-03e3e8f4177b','column3','3','string',0,'',NULL); 
     456INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348','reportTitle','Subtotals, Totals, and Amount Due','string',0,'Report','Report Title'); 
     457INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348','showWhat','lineitems','string',0,'',NULL); 
     458INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348','column1','11','string',0,'',NULL); 
     459INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348','column2','1','string',0,'',NULL); 
     460INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:8a9cf2d6-d5f0-54ca-1b89-8207dfa4c348','column3','3','string',0,'',NULL); 
     461INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','reportTitle','Totals Grouped by Sales Order Lead Source','string',0,'Report','Report Title'); 
     462INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','showWhat','invoices','string',0,'',NULL); 
     463INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','column1','11','string',0,'',NULL); 
     464INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','column2','1','string',0,'',NULL); 
     465INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','column3','3','string',0,'',NULL); 
     466INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:3cb9ae81-0838-863e-0185-1f46224cbe00','group1','15','string',0,'',NULL); 
     467INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','reportTitle','Totals Grouped by Payment Method','string',0,'Report','Report Title'); 
     468INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','showWhat','invoices','string',0,'',NULL); 
     469INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','column1','11','string',0,'',NULL); 
     470INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','column2','1','string',0,'',NULL); 
     471INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','column3','3','string',0,'',NULL); 
     472INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:67dca680-14ba-d4e7-4926-b90c65495f48','group1','16','string',0,'',NULL); 
     473INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140','reportTitle','Totals Grouped by Shipping Method','string',0,'Report','Report Title'); 
     474INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140','showWhat','invoices','string',0,'',NULL); 
     475INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140','column1','1','string',0,'',NULL); 
     476INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140','coumn2','7','string',0,'',NULL); 
     477INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:5dc66c67-1e98-7f85-6e89-5ab5d7795140','group1','17','string',0,'',NULL); 
     478INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:d97334ef-0139-f178-fe36-c38e151cc60e','reportTitle','Tax Totals','string',0,'Report','Report Title'); 
     479INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:d97334ef-0139-f178-fe36-c38e151cc60e','showWhat','invoices','string',0,'',NULL); 
     480INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:d97334ef-0139-f178-fe36-c38e151cc60e','column1','11','string',0,'',NULL); 
     481INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:d97334ef-0139-f178-fe36-c38e151cc60e','column2','1','string',0,'',NULL); 
     482INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:d97334ef-0139-f178-fe36-c38e151cc60e','column3','5','string',0,'',NULL); 
     483INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','reportTitle','Invoice','string',1,'Invoice','Title printed on reports'); 
     484INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','printLogo','1','bool',1,'1','Should the logo print (1 = yes, 0 = no)'); 
     485INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','printCompanyInfo','1','bool',1,'1','Should the top company information print (1 = yes, 0 = no)'); 
     486INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','leftTopBox','billto','string',1,'billto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     487INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','leftTopBoxTitle','SOLD TO','string',1,'SOLD TO','Title of Left Top Header Box'); 
     488INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','rightTopBox','shipto','string',1,'shipto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     489INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','rightTopBoxTitle','SHIP TO','string',1,'SHIP TO','Title of Right Top Header Box'); 
     490INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','templateFormatting','0','bool',1,'0','Should PDF remove lines and dark titles (1 = remove, 0 = keep)'); 
     491INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:44b21461-6e67-c284-0ccf-36ab1af47c9b','templateUUID','','string',0,'','Optional UUID of file record for PDF to be used as background template'); 
     492INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','reportTitle','Packing List','string',1,'Packing List','Title printed on reports'); 
     493INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','printLogo','1','bool',1,'1','Should the logo print (1 = yes, 0 = no)'); 
     494INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','printCompanyInfo','1','bool',1,'1','Should the top company information print (1 = yes, 0 = no)'); 
     495INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','leftTopBox','billto','string',1,'billto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     496INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','leftTopBoxTitle','SOLD TO','string',1,'SOLD TO','Title of Left Top Header Box'); 
     497INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','rightTopBox','shipto','string',1,'shipto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     498INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','rightTopBoxTitle','SHIP TO','string',1,'SHIP TO','Title of Right Top Header Box'); 
     499INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','templateFormatting','0','bool',1,'0','Should PDF remove lines and dark titles (1 = remove, 0 = keep)'); 
     500INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:6bdef1ac-2f74-4d20-411a-3e48531dae73','templateUUID','','string',0,'','Optional UUID of file record for PDF to be used as background template'); 
     501INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','reportTitle','Quote','string',1,'Quote','Title printed on reports'); 
     502INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','printLogo','1','bool',1,'1','Should the logo print (1 = yes, 0 = no)'); 
     503INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','printCompanyInfo','1','bool',1,'1','Should the top company information print (1 = yes, 0 = no)'); 
     504INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','leftTopBox','billto','string',1,'billto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     505INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','leftTopBoxTitle','SOLD TO','string',1,'SOLD TO','Title of Left Top Header Box'); 
     506INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','rightTopBox','shipto','string',1,'shipto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     507INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','rightTopBoxTitle','SHIP TO','string',1,'SHIP TO','Title of Right Top Header Box'); 
     508INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','templateFormatting','0','bool',1,'0','Should PDF remove lines and dark titles (1 = remove, 0 = keep)'); 
     509INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:b683e2f0-e52b-4dd4-33e1-7566616893ca','templateUUID','','string',0,'','Optional UUID of file record for PDF to be used as background template'); 
     510INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','reportTitle','Work Order','string',1,'Work Order','Title printed on reports'); 
     511INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','printLogo','1','bool',1,'1','Should the logo print (1 = yes, 0 = no)'); 
     512INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','printCompanyInfo','1','bool',1,'1','Should the top company information print (1 = yes, 0 = no)'); 
     513INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','leftTopBox','billto','string',1,'billto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     514INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','leftTopBoxTitle','SOLD TO','string',1,'SOLD TO','Title of Left Top Header Box'); 
     515INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','rightTopBox','shipto','string',1,'shipto','Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)'); 
     516INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','rightTopBoxTitle','SHIP TO','string',1,'SHIP TO','Title of Right Top Header Box'); 
     517INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','templateFormatting','0','bool',1,'0','Should PDF remove lines and dark titles (1 = remove, 0 = keep)'); 
     518INSERT INTO `reportsettings` (reportuuid, name, value, type, required, defaultvalue, description)  VALUES ('rpt:30a56a65-8673-b3c0-cd50-6546968b4d37','templateUUID','','string',0,'','Optional UUID of file record for PDF to be used as background template'); 
     519--end reportsettings INSERT-- 
    370520--role UPDATE-- 
    371521UPDATE `roles` SET `uuid`='role:3403a7e0-adb1-4d0b-3c6e-6d6bbe177d52' WHERE `id`='10'; 
     
    386536UPDATE `shippingmethods` SET `uuid`='shp:f34a3e10-e782-2675-f041-71f5c88f5aa9' WHERE `name`='FedEx Priority Overnight AM'; 
    387537UPDATE `shippingmethods` SET `uuid`='shp:e2e43816-667a-fdf3-6bec-4456bcf8bef0' WHERE `name`='FedEx Standard Overnight'; 
    388 UPDATE `shippingmethods` SET `uuid`='shp:0f07f7fd-0352-8df7-8294-a57e5e375808' WHERE `name`='UPS 2nd Day Air';  
     538UPDATE `shippingmethods` SET `uuid`='shp:0f07f7fd-0352-8df7-8294-a57e5e375808' WHERE `name`='UPS 2nd Day Air'; 
    389539UPDATE `shippingmethods` SET `uuid`='shp:6ef11711-7335-3e90-cf27-df5ea23c1480' WHERE `name`='UPS 3 Day Select'; 
    390540UPDATE `shippingmethods` SET `uuid`='shp:1a0c53bd-6754-7d9f-4bea-bad57628187a' WHERE `name`='UPS Ground (Com)'; 
  • trunk/phpbms/modules/bms/products_saleshistory.php

    r606 r693  
    4040        include("include/fields.php"); 
    4141 
    42         if(!hasRights("role:259ead9f-100b-55b5-508a-27e33a6216bf")) goURL(APP_PATH."noaccess.php"); 
    43  
    44         if(!isset($_POST["fromdate"])) $_POST["fromdate"]=dateToString(strtotime("-1 year")); 
    45         if(!isset($_POST["todate"])) $_POST["todate"]=dateToString(mktime()); 
    46         if(!isset($_POST["status"])) $_POST["status"]="Orders/Invoices"; 
    47         if(!isset($_POST["command"])) $_POST["command"]="show"; 
    48         if(!isset($_POST["date_order"])) $_POST["date_order"]="DESC"; 
     42        if(!hasRights("role:259ead9f-100b-55b5-508a-27e33a6216bf")) 
     43            goURL(APP_PATH."noaccess.php"); 
     44 
     45        if(!isset($_POST["fromdate"])) 
     46            $_POST["fromdate"] = dateToString(strtotime("-1 year")); 
     47 
     48        if(!isset($_POST["todate"])) 
     49            $_POST["todate"] = dateToString(mktime()); 
     50 
     51        if(!isset($_POST["status"])) 
     52            $_POST["status"] = "Orders and Invoices"; 
     53 
     54        if(!isset($_POST["command"])) 
     55            $_POST["command"] = "show"; 
     56 
     57        if(!isset($_POST["date_order"])) 
     58            $_POST["date_order"] = "DESC"; 
    4959 
    5060        if($_POST["command"]=="print")  { 
    51                         $_SESSION["printing"]["whereclause"]="WHERE products.id=".$_GET["id"]; 
    52                         $_SESSION["printing"]["dataprint"]="Single Record"; 
    53                         $fromProduct=true; 
    54                         require("report/products_saleshistory.php"); 
     61 
     62            $_SESSION["printing"]["whereclause"]="products.id=".$_GET["id"]; 
     63            $_SESSION["printing"]["dataprint"]="Single Record"; 
     64 
     65            goURL("report/products_saleshistory.php?rid=".urlencode("rpt:a278af28-9c34-da2e-d81b-4caa36dfa29f")."&tid=".urlencode("tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34")."&status=".urlencode($_POST["status"])."&fromdate=".urlencode($_POST["fromdate"])."&todate=".urlencode($_POST["todate"])); 
     66 
    5567        } else { 
    56         $thestatus="(invoices.type =\""; 
    57         switch($_POST["status"]){ 
    58                 case "Orders/Invoices": 
    59                         $thestatus.="Order\" or invoices.type=\"Invoice\")"; 
    60                         $searchdate="orderdate"; 
    61                 break; 
     68 
     69            $thestatus="(invoices.type =\""; 
     70            switch($_POST["status"]){ 
     71 
     72                case "Orders and Invoices": 
     73                    $thestatus.="Order\" or invoices.type=\"Invoice\")"; 
     74                    $searchdate="orderdate"; 
     75                    break; 
     76 
    6277                case "Invoices": 
    63                         $thestatus.="Invoice\")"; 
    64                         $searchdate="invoicedate"; 
    65                 break; 
     78                    $thestatus.="Invoice\")"; 
     79                    $searchdate="invoicedate"; 
     80                    break; 
     81 
    6682                case "Orders": 
    67                         $thestatus.="Order\")"; 
    68                         $searchdate="orderdate"; 
    69                 break; 
    70         } 
     83                    $thestatus.="Order\")"; 
     84                    $searchdate="orderdate"; 
     85                    break; 
     86 
     87            }//endswitch 
    7188        $dateOrder = ($_POST['date_order'] == 'DESC') ? 'ASC' : 'DESC'; 
    7289 
     
    132149                   <label for="status">type</label><br /> 
    133150                   <select name="status" id="status"> 
    134                                 <option value="Orders/Invoices" <?php if($_POST["status"]=="Orders/Invoices") echo "selected=\"selected\""?>>Orders/Invoices</option> 
     151                                <option value="Orders and Invoices" <?php if($_POST["status"]=="Orders and Invoices") echo "selected=\"selected\""?>>Orders and Invoices</option> 
    135152                                <option value="Invoices" <?php if($_POST["status"]=="Invoices") echo "selected=\"selected\""?>>Invoices</option> 
    136153                                <option value="Orders" <?php if($_POST["status"]=="Orders") echo "selected=\"selected\""?>>Orders</option> 
     
    143160 
    144161                <p id="printP"><br /><input id="print" name="command" type="submit" value="print" class="Buttons" /></p> 
    145                 <p id="changeTimelineP"><br /><input name="command" type="submit" value="change timeframe/view" class="smallButtons" /></p> 
     162                <p id="changeTimelineP"><br /><input name="command" type="submit" value="update" class="smallButtons" /></p> 
    146163                <input name="date_order" id="date_order" type="hidden" value="<?php echo $_POST["date_order"]; ?>" /> 
    147164        </div> 
  • trunk/phpbms/modules/bms/report/aritems_clientstatement.php

    r673 r693  
    5050        var $showClosed = false; 
    5151 
    52         function aritemsClientStatements($db, $statementDate = NULL, $showPayments = true, $showClosed = false){ 
    53  
    54                 parent::phpbmsReport($db); 
     52        function aritemsClientStatements($db, $reportUUID, $tabledefUUID, $statementDate = NULL, $showPayments = true, $showClosed = false){ 
     53 
     54                parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
    5555 
    5656                if($statementDate) 
     
    6969 
    7070                if($whereclause) 
    71                         $this->whereclause = $whereclause; 
    72  
    73                 if(!$this->whereclause) 
    74                         $this->whereclause = " 
     71                        $this->whereClause = $whereclause; 
     72 
     73                if(!$this->whereClause) 
     74                        $this->whereClause = " 
    7575                                aritems.status = 'open' 
    7676                                AND aritems.posted = 1"; 
     
    108108                                        ON clients.salesmanagerid = users.uuid"; 
    109109 
    110                 $this->sortorder = 'if(clients.lastname!="",concat(clients.lastname,", ",clients.firstname,if(clients.company!="",concat(" (",clients.company,")"),"")),clients.company)'; 
     110                $this->sortOrder = 'if(clients.lastname!="",concat(clients.lastname,", ",clients.firstname,if(clients.company!="",concat(" (",clients.company,")"),"")),clients.company)'; 
    111111 
    112112                $querystatement = $this->assembleSQL($querystatement); 
     
    134134                //uncomment the following line to help troubleshoot formatting 
    135135                //$pdf->borderDebug = 1; 
    136                 $pdf->hasComapnyHeader = true; 
     136                $pdf->logoInHeader = true; 
     137                $pdf->companyInfoInHeader = true; 
    137138                $pdf->SetMargins(); 
    138139 
     
    608609if(!isset($noOutput)){ 
    609610 
     611    //IE needs caching to be set to private in order to display PDFS 
     612    session_cache_limiter('private'); 
     613 
     614    //set encoding to latin1 (fpdf doesnt like utf8) 
     615    $sqlEncoding = "latin1"; 
     616    require_once("../../../include/session.php"); 
     617 
     618    checkForReportArguments(); 
     619 
     620    $report = new aritemsClientStatements($db, $_GET["rid"], $_GET["tid"]); 
     621 
    610622        if(isset($_GET["cmd"])){ 
    611623 
     
    616628 
    617629        if(isset($_POST["command"])) { 
    618  
    619                 session_cache_limiter('private'); 
    620  
    621                 //set encoding to latin1 (fpdf doesnt like utf8) 
    622                 $sqlEncoding = "latin1"; 
    623                 require_once("../../../include/session.php"); 
    624  
    625                 $report = new aritemsClientStatements($db); 
    626630 
    627631                switch($_POST["command"]){ 
     
    635639        } else { 
    636640 
    637                 require_once("../../../include/session.php"); 
    638  
    639                 $report = new aritemsClientStatements($db); 
    640  
    641641                $report->showOptions(); 
    642642 
     
    644644 
    645645}//end if 
     646 
     647/** 
     648 * When adding a new report record, the add/edit needs to know what the class 
     649 * name is so that it can instantiate it, and grab it's default settings. 
     650 */ 
     651if(isset($addingReportRecord)) 
     652    $reportClass ="aritemsClientStatements"; 
     653 
    646654?> 
  • trunk/phpbms/modules/bms/report/aritems_summary.php

    r633 r693  
    5959 
    6060 
    61         function aritemsSummary($db, $statementDate = NULL, $showPayments = "new", $showClosed = false){ 
    62  
    63                 parent::phpbmsReport($db); 
     61        function aritemsSummary($db, $reportUUID, $tabledefUUID, $statementDate = NULL, $showPayments = "new", $showClosed = false){ 
     62 
     63                parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
    6464 
    6565                if($statementDate) 
     
    7878 
    7979                if($whereclause) 
    80                         $this->whereclause = $whereclause; 
    81  
    82                 if(!$this->whereclause) 
    83                         $this->whereclause = " 
     80                        $this->whereClause = $whereclause; 
     81 
     82                if(!$this->whereClause) 
     83                        $this->whereClause = " 
    8484                                aritems.status = 'open' 
    8585                                AND aritems.posted = 1"; 
     
    116116                                        ON clients.salesmanagerid = users.uuid"; 
    117117 
    118                 $this->sortorder = 'if(clients.lastname!="",concat(clients.lastname,", ",clients.firstname,if(clients.company!="",concat(" (",clients.company,")"),"")),clients.company)'; 
     118                $this->sortOrder = 'if(clients.lastname!="",concat(clients.lastname,", ",clients.firstname,if(clients.company!="",concat(" (",clients.company,")"),"")),clients.company)'; 
    119119 
    120120                $querystatement = $this->assembleSQL($querystatement); 
     
    573573        }//endif 
    574574 
     575        session_cache_limiter('private'); 
     576        //set encoding to latin1 (fpdf doesnt like utf8) 
     577        $sqlEncoding = "latin1"; 
     578        require_once("../../../include/session.php"); 
     579 
     580        checkForReportArguments(); 
     581 
     582        $report = new aritemsSummary($db, $_GET["rid"], $_GET["tid"]); 
     583 
    575584        if(isset($_POST["command"])) { 
    576  
    577                 session_cache_limiter('private'); 
    578  
    579                 //set encoding to latin1 (fpdf doesnt like utf8) 
    580                 $sqlEncoding = "latin1"; 
    581                 require_once("../../../include/session.php"); 
    582  
    583                 $report = new aritemsSummary($db); 
    584585 
    585586                switch($_POST["command"]){ 
     
    593594        } else { 
    594595 
    595                 require_once("../../../include/session.php"); 
    596  
    597                 $report = new aritemsSummary($db); 
    598  
    599596                $report->showOptions(); 
    600597 
  • trunk/phpbms/modules/bms/report/clients_purchasehistory.php

    r607 r693  
    3838*/ 
    3939 
    40 if(!isset($fromClient)) { 
    41         require_once("../../../include/session.php"); 
    42 } 
    43  
    44 class purchaseHistoryReport{ 
    45  
    46         var $whereclause=""; 
    47         var $sortorder=" ORDER BY IF(clients.lastname!=\"\",concat(clients.lastname,\", \",clients.firstname,if(clients.company!=\"\",concat(\" (\",clients.company,\")\"),\"\")),clients.company) "; 
    48         var $fromdate; 
    49         var $todate; 
    50         var $view; 
    51  
    52         var $clientQuery; 
    53  
    54         function initialize($variables,$db){ 
    55  
    56                 $this->db = $db; 
    57                 $this->fromdate=$variables["fromdate"]; 
    58                 $this->todate=$variables["todate"]; 
    59                 $this->view=$variables["status"]; 
    60  
    61                 $this->whereclause=$_SESSION["printing"]["whereclause"]; 
    62                 if(isset($_SESSION["printing"]["sortorder"])) 
    63                         if ($_SESSION["printing"]["sortorder"]) 
    64                                 $this->sortorder=$_SESSION["printing"]["sortorder"]; 
    65  
    66                 if($this->whereclause=="") $this->whereclause="WHERE clients.id!=-1"; 
    67                 $this->whereclause=" WHERE (".substr($this->whereclause,6).") "; 
    68  
    69                 $querystatement = " 
    70                         SELECT 
    71                                 `clients`.`id`, 
    72                                 IF(clients.lastname!=\"\",concat(clients.lastname,\", \",clients.firstname,if(clients.company!=\"\",concat(\" (\",clients.company,\")\"),\"\")),clients.company) as thename 
    73                      FROM 
    74                                 `clients` ".$this->whereclause.$this->sortorder; 
    75  
    76                 $queryresult=$this->db->query($querystatement); 
    77  
    78                 $this->clientQuery=$queryresult; 
    79         } 
    80  
    81  
    82         function showPurchaseHistory($id){ 
    83  
    84                 $thestatus="(invoices.type =\""; 
    85                 switch($this->view){ 
    86                         case "Orders/Invoices": 
    87                                 $thestatus.="Order\" or invoices.type=\"Invoice\")"; 
    88                                 $searchdate="orderdate"; 
    89                         break; 
    90                         case "Invoices": 
    91                                 $thestatus.="Invoice\")"; 
    92                                 $searchdate="invoicedate"; 
    93                         break; 
    94                         case "Orders": 
    95                                 $thestatus.="Order\")"; 
    96                                 $searchdate="orderdate"; 
    97                         break; 
    98                 } 
    99  
    100         $mysqlfromdate=sqlDateFromString($_POST["fromdate"]); 
    101         $mysqltodate=sqlDateFromString($_POST["todate"]); 
     40if(!class_exists("phpbmsReport")) 
     41    include("../../../report/report_class.php"); 
     42 
     43class purchaseHistoryReport extends phpbmsReport{ 
     44 
     45    var $fromDate; 
     46    var $toDate; 
     47    var $view; 
     48    var $clientQueryresult; 
     49    var $dataPrint; 
     50 
     51    function purchaseHistoryReport($db, $reportUUID, $tabledefUUID){ 
     52 
     53        parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     54 
     55        //$this->checkForDefaultSettings(); 
     56 
     57    }//end function init 
     58 
     59 
     60    function initialize($variables){ 
     61 
     62        if(!isset($variables["fromdate"]) || !isset($variables["todate"]) || !isset($variables["status"])) 
     63            $error = new appError(300, "Missing Passed Parameters"); 
     64 
     65        $this->fromDate = $variables["fromdate"]; 
     66        $this->toDate = $variables["todate"]; 
     67        $this->view = $variables["status"]; 
     68 
     69        $this->dataPrint = $_SESSION["printing"]["dataprint"]; 
     70 
     71        if(!$this->sortOrder) 
     72            $this->sortOrder = " ORDER BY clients.company, clients.firstname, clients.lastname"; 
     73 
     74        if(!$this->whereClause) 
     75            $this->whereClause = "clients.id!=-1"; 
     76 
     77        $this->whereClause = " WHERE (".$this->whereClause.") "; 
     78 
     79        $querystatement = " 
     80            SELECT 
     81                `clients`.`uuid`, 
     82                IF(clients.company != '', CONCAT(clients.company,IF(clients.lastname != '' OR clients.firstname != '', CONCAT(' (',if(clients.lastname != '', clients.lastname, '{blank}'),', ',if(clients.firstname != '', clients.firstname, '{blank}'),')'), '')), IF(clients.lastname != '' OR clients.firstname != '', CONCAT(if(clients.lastname != '', clients.lastname, '{blank}'),', ',if(clients.firstname != '', clients.firstname, '{blank}')), '')) AS thename 
     83             FROM 
     84                `clients` 
     85            ".$this->whereClause.$this->sortOrder; 
     86 
     87        $this->clientQueryresult = $this->db->query($querystatement); 
     88 
     89    }//end function initialize 
     90 
     91 
     92    function generateSingleClientHistory($clientUUID){ 
     93 
     94        $theStatus = "(invoices.type = '"; 
     95 
     96        switch($this->view){ 
     97 
     98            case "Orders and Invoices": 
     99                $theStatus .= "Order' OR invoices.type ='Invoice')"; 
     100                $searchDate = "orderdate"; 
     101                break; 
     102 
     103            case "Invoices": 
     104                $theStatus .= "Invoice')"; 
     105                $searchDate = "invoicedate"; 
     106                break; 
     107 
     108            case "Orders": 
     109                $theStatus .= "Order')"; 
     110                $searchDate = "orderdate"; 
     111                break; 
     112 
     113        }//endswitch 
     114 
     115        $mysqlFromDate = sqlDateFromString($this->fromDate); 
     116        $mysqlToDate = sqlDateFromString($this->toDate); 
    102117 
    103118        $querystatement = " 
    104                 SELECT 
    105                         invoices.id, 
    106                         if(invoices.type=\"Invoice\",invoices.invoicedate,invoices.orderdate) as thedate, 
    107                         if(invoices.type=\"Invoice\",invoices.invoicedate,invoices.orderdate) as formateddate, 
    108                         invoices.type, 
    109                         products.partname as partname, 
    110                         products.partnumber as partnumber, 
    111                         lineitems.quantity as qty, 
    112                         lineitems.unitprice*lineitems.quantity as extended, 
    113                         lineitems.unitprice as price 
    114                 FROM 
    115                         ((`clients` INNER JOIN `invoices` ON `clients`.`uuid`=`invoices`.`clientid`) 
    116                                 INNER JOIN `lineitems` ON `invoices`.`id`=`lineitems`.`invoiceid`) 
    117                                         INNER JOIN `products` ON `lineitems`.`productid`=`products`.`uuid` 
    118                 WHERE `clients`.`id`='".$id."' 
    119                 AND ".$thestatus." 
    120                 HAVING 
    121                 thedate >=\"".$mysqlfromdate."\" 
    122                 and thedate <=\"".$mysqltodate."\" 
    123                 ORDER BY thedate,invoices.id;"; 
    124                 $thequery=$this->db->query($querystatement); 
    125  
    126                 $thequery? $numrows=$this->db->numRows($thequery): $numrows=0; 
    127 ?> 
    128         <table border="0" cellpadding="0" cellspacing="0" > 
     119            SELECT 
     120                invoices.id, 
     121                if(invoices.type = 'Invoice', invoices.invoicedate, invoices.orderdate) AS thedate, 
     122                invoices.type, 
     123                products.partname AS partname, 
     124                products.partnumber AS partnumber, 
     125                lineitems.quantity AS qty, 
     126                lineitems.unitprice*lineitems.quantity AS extended, 
     127                lineitems.unitprice AS price 
     128            FROM 
     129                ((`clients` INNER JOIN `invoices` ON `clients`.`uuid`=`invoices`.`clientid`) 
     130                    INNER JOIN `lineitems` ON `invoices`.`id`=`lineitems`.`invoiceid`) 
     131                    INNER JOIN `products` ON `lineitems`.`productid`=`products`.`uuid` 
     132            WHERE 
     133                `clients`.`uuid`='".$clientUUID."' 
     134                AND ".$theStatus." 
     135            HAVING 
     136                thedate >= '".$mysqlFromDate."' 
     137                AND thedate <= '".$mysqlToDate."' 
     138            ORDER BY 
     139                thedate, 
     140                invoices.id"; 
     141 
     142        $queryresult = $this->db->query($querystatement); 
     143 
     144        ob_start(); 
     145 
     146        ?> 
     147        <table border="0" cellpadding="0" cellspacing="0"> 
     148            <thead> 
    129149                <tr> 
    130                         <th align="left" nowrap="nowrap" colspan="3">invoice</th> 
    131                         <th align="left" nowrap="nowrap" colspan="3">product</th> 
    132                         <th align="left" nowrap="nowrap" colspan="2">line item</th> 
     150                        <th align="left" colspan="3">invoice</th> 
     151                        <th align="left" colspan="3">product</th> 
     152                        <th align="left" nowrap="nowrap" colspan="2" class="lastHeader">line item</th> 
    133153                </tr> 
    134154                <tr> 
     
    136156                        <th align="left" nowrap="nowrap" >type</th> 
    137157                        <th align="left" nowrap="nowrap" >date</th> 
    138                         <th align="left" nowrap="nowrap" >part num.</th> 
     158                        <th align="left" nowrap="nowrap" >part #</th> 
    139159                        <th width="100%" nowrap="nowrap" align="left">name</th> 
    140160                        <th align="right" nowrap="nowrap" >price</th> 
    141                         <th align="center" nowrap="nowrap" >qty.</th> 
    142                         <th align="right" nowrap="nowrap" >ext.</th> 
    143                 </tr> 
    144     <?php 
    145         $totalextended=0; 
    146         while ($therecord=$this->db->fetchArray($thequery)){ 
    147                 $totalextended=$totalextended+$therecord["extended"]; 
    148         ?> 
    149         <tr> 
    150                 <td align="left" nowrap="nowrap"><?php echo $therecord["id"]?$therecord["id"]:"&nbsp;" ?></td> 
    151                 <td align="left" nowrap="nowrap"><?php echo $therecord["type"]?$therecord["type"]:"&nbsp;" ?></td> 
    152                 <td align="left" nowrap="nowrap"><?php echo $therecord["formateddate"]?$therecord["formateddate"]:"&nbsp;" ?></td> 
    153                 <td nowrap="nowrap"><?php echo $therecord["partnumber"]?></td> 
    154                 <td nowrap="nowrap"><?php echo $therecord["partname"]?></td> 
    155                 <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["price"])?></td> 
    156                 <td align="center" nowrap="nowrap"><?php echo $therecord["qty"]?></td> 
    157                 <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extended"])?></td> 
    158         </tr> 
    159         <?php }//end while ?> 
    160         <tr> 
    161          <td align="center" class="grandtotals">&nbsp;</td> 
    162          <td align="center" class="grandtotals">&nbsp;</td> 
    163          <td align="center" class="grandtotals">&nbsp;</td> 
    164          <td class="grandtotals">&nbsp;</td> 
    165          <td class="grandtotals">&nbsp;</td> 
    166          <td align="right" class="grandtotals">&nbsp;</td> 
    167          <td align="center" class="grandtotals">&nbsp;</td> 
    168          <td align="right" class="grandtotals"><?php echo numberToCurrency($totalextended)?></td> 
    169         </tr> 
    170    </table>     <?php 
    171         }//end fucntion showSalesHistory($id) 
    172  
    173         function showReport(){ 
    174         ?> 
    175         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    176 <html> 
    177 <head> 
    178 <title>Client Purchase History</title> 
    179 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    180 <style type="text/css"> 
    181 <!-- 
    182 BODY,TH,TD,H1,H2,h3{ 
    183         font-size : 11px; 
    184         font-family : sans-serif; 
    185         color : Black; 
    186 } 
    187 H1,H2, LI{ 
    188         font-size:18px; 
    189         border-bottom:4px solid black; 
    190         margin:0px; 
    191 } 
    192 H2, LI{ font-size:11px; border-bottom-width:2px; margin-bottom:10px;} 
    193 H3{ font-size:14px; margin-bottom:2px;} 
    194 div {padding:5px;} 
    195  
    196 UL{margin:0;padding:0;} 
    197 LI{float:left;display:inline;padding-left:10px;} 
    198  
    199 TABLE{border:3px solid black;border-bottom-width:1px;border-right-width:1px;} 
    200 TH, TD{ padding:2px; border-right:1px solid black;border-bottom:1px solid black;} 
    201 TH { 
    202         background-color:#EEEEEE; 
    203         font-size:12px; 
    204         font-weight: bold; 
    205         border-bottom-width:3px; 
    206 } 
    207  
    208 .grandtotals{font-size:12px; border-top:3px double black; font-weight:bold; padding-top:8px;padding-bottom:8px; background-color:#EEEEEE;} 
    209  
    210 --> 
    211 </style> 
    212 </head> 
    213 <body> 
    214 <h1>Client Purchase History</h1> 
     161                        <th align="right" nowrap="nowrap" >qty.</th> 
     162                        <th align="right" nowrap="nowrap" class="lastHeader">ext.</th> 
     163                </tr> 
     164            </thead> 
     165            <tbody> 
     166        <?php 
     167 
     168            $totalextended = 0; 
     169 
     170            while($therecord = $this->db->fetchArray($queryresult)){ 
     171 
     172                $totalextended += $therecord["extended"]; 
     173 
     174                ?> 
     175                    <tr> 
     176                        <td align="left" nowrap="nowrap"><?php echo $therecord["id"]?$therecord["id"]:"&nbsp;" ?></td> 
     177                        <td align="left" nowrap="nowrap"><?php echo $therecord["type"]?formatVariable($therecord["type"]):"&nbsp;" ?></td> 
     178                        <td align="left" nowrap="nowrap"><?php echo $therecord["thedate"]?formatFromSQLDate($therecord["thedate"]):"&nbsp;" ?></td> 
     179                        <td nowrap="nowrap"><?php echo formatVariable($therecord["partnumber"]) ?></td> 
     180                        <td nowrap="nowrap"><?php echo formatVariable($therecord["partname"]) ?></td> 
     181                        <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["price"])?></td> 
     182                        <td align="right" nowrap="nowrap"><?php echo $therecord["qty"]?></td> 
     183                        <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extended"])?></td> 
     184                    </tr> 
     185                <?php 
     186 
     187            }//endwhile 
     188        ?> 
     189                <tr class="grandTotals"> 
     190                    <td colspan="7" align="right">total</td> 
     191                    <td align="right"><?php echo numberToCurrency($totalextended)?></td> 
     192                </tr> 
     193 
     194            </tbody> 
     195        </table><?php 
     196 
     197        $output = ob_get_contents(); 
     198        ob_end_clean(); 
     199 
     200        return $output; 
     201 
     202    }//end function generateSingleClientHistory 
     203 
     204 
     205 
     206    function generate(){ 
     207 
     208 
     209        ob_start(); 
     210        ?> 
     211 
     212        <h1>Client Purchase History</h1> 
    215213 
    216214        <ul> 
    217                 <li> 
    218                         <strong> 
    219                         source:<br /> 
    220                         <?php echo $_SESSION["printing"]["dataprint"]?> 
    221                         </strong> 
    222                 </li> 
    223                 <li> 
    224                         <strong> 
    225                         date generated:<br /> 
    226                         <?php echo dateToString(mktime())." ".timeToString(mktime());?> 
    227                         </strong> 
    228                 </li> 
    229                 <li style="padding-left:30px;padding-right:20px;"> 
    230                         <strong> 
    231                         view:<br /> 
    232                         <?php echo $this->view?> 
    233                         </strong> 
    234                 </li> 
    235                 <li> 
    236                         <strong> 
    237                         from:<br /> 
    238                         <?php echo $this->fromdate?> 
    239                         </strong> 
    240                 </li> 
    241                 <li> 
    242                         <strong> 
    243                         to:<br /> 
    244                         <?php echo $this->todate?> 
    245                         </strong> 
    246                 </li> 
    247         </ul><br /><br /> 
    248  
    249 <?php while($therecord=$this->db->fetchArray($this->clientQuery)){?> 
    250         <h3><?php echo $therecord["thename"]?></h3> 
    251 <?php $this->showPurchaseHistory($therecord["id"]);}//end while?> 
    252 </body> 
    253 </html> 
    254         <?php 
    255         } 
    256 }//end class 
    257  
    258 if(isset($_POST["command"])){ 
    259         $myreport= new purchaseHistoryReport(); 
    260         $myreport->initialize($_POST,$db); 
    261  
    262         $myreport->showReport(); 
    263 } else { 
    264                 require("include/fields.php"); 
    265  
    266                 $pageTitle = "Client Purchase History"; 
    267                 $phpbms->cssIncludes[] = "pages/historyreports.css"; 
    268                 $phpbms->showMenu = false; 
    269  
    270                 //Form Elements 
    271                 //============================================================== 
    272                 $theform = new phpbmsForm(); 
    273  
    274  
    275                 $thedate = dateToString( mktime(0,0,0,date("m"),1),"SQL" ); 
    276                 $theinput = new inputDatePicker("fromdate", $thedate, "from",true); 
    277                 $theform->addField($theinput); 
    278  
    279                 $thedate = dateToString( mktime(0,0,0,date("m")+1,0,date("Y")), "SQL" ); 
    280                 $theinput = new inputDatePicker("todate", $thedate, "to",true); 
    281                 $theform->addField($theinput); 
    282  
    283                 $theform->jsMerge(); 
    284                 //============================================================== 
    285                 //End Form Elements 
    286  
    287                 include("header.php"); 
    288 ?> 
    289 <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="totals" onsubmit="return validateForm(this)"> 
    290 <div class="bodyline" id="reportOptions"> 
    291         <h1 id="topTitle"><span>Product Sales History Options</span></h1> 
    292                 <fieldset> 
    293                         <legend>time frame</legend> 
    294  
    295                         <p id="fromP"><?php $theform->showField("fromdate");?></p> 
    296  
    297                         <p><?php $theform->showField("todate");?></p> 
    298                 </fieldset> 
    299  
    300                 <p> 
    301                         <label for="status">include products from...<br /></label> 
    302                    <select id="status" name="status"> 
    303                                 <option value="Orders/Invoices" selected="selected">Orders/Invoices</option> 
    304                                 <option value="Invoices">Invoices</option> 
    305                                 <option value="Orders">Orders</option> 
    306                    </select> 
    307                 </p> 
    308  
    309                 <div align="right"> 
    310                         <input name="command" type="submit" class="Buttons" id="print" value="print" /> 
    311                         <input name="cancel" type="button" class="Buttons" id="cancel" value="cancel" onclick="window.close();" /> 
    312                 </div> 
    313 </div> 
    314 </form> 
    315 <?php 
    316 include("footer.php"); 
    317 }?> 
     215            <li> 
     216                source:<br /> 
     217                <?php echo formatVariable($this->dataPrint); ?> 
     218            </li> 
     219            <li> 
     220                date generated:<br /> 
     221                <?php echo dateToString(mktime())." ".timeToString(mktime()); ?> 
     222            </li> 
     223            <li> 
     224                view:<br /> 
     225                <?php echo $this->view; ?> 
     226            </li> 
     227            <li> 
     228                from:<br /> 
     229                <?php echo $this->fromDate; ?> 
     230            </li> 
     231            <li> 
     232                to:<br /> 
     233                <?php echo $this->toDate; ?> 
     234            </li> 
     235        </ul> 
     236 
     237        <?php 
     238 
     239        $this->reportOutput = ob_get_contents(); 
     240        ob_end_clean(); 
     241 
     242        while($therecord = $this->db->fetchArray($this->clientQueryresult)){ 
     243 
     244            $this->reportOutput .= '<h2>'.$therecord["thename"].'</h2>'; 
     245 
     246            $this->reportOutput .= $this->generateSingleClientHistory($therecord["uuid"]); 
     247 
     248        }//endwhile 
     249 
     250    }//end function generate 
     251 
     252 
     253    function output(){ 
     254 
     255        global $phpbms; 
     256        $db = &$this->db; 
     257 
     258        $phpbms->cssIncludes[] = "reports.css"; 
     259        $phpbms->cssIncludes[] = "pages/bms/clienthistoryreport.css"; 
     260 
     261        $phpbms->showMenu = false; 
     262        $phpbms->showFooter = false; 
     263 
     264        include("header.php"); 
     265 
     266        echo $this->reportOutput; 
     267 
     268        include("footer.php"); 
     269 
     270    }//end function output 
     271 
     272 
     273    function displayOptions(){ 
     274 
     275        global $phpbms; 
     276        $db = &$this->db; 
     277 
     278        require("include/fields.php"); 
     279 
     280        $pageTitle = "Client Purchase History"; 
     281        $phpbms->cssIncludes[] = "pages/historyreports.css"; 
     282        $phpbms->showMenu = false; 
     283 
     284        //Form Elements 
     285        //============================================================== 
     286        $theform = new phpbmsForm(); 
     287 
     288        $thedate = dateToString( mktime(0,0,0,date("m"),1),"SQL" ); 
     289        $theinput = new inputDatePicker("fromdate", $thedate, "from",true); 
     290        $theform->addField($theinput); 
     291 
     292        $thedate = dateToString( mktime(0,0,0,date("m")+1,0,date("Y")), "SQL" ); 
     293        $theinput = new inputDatePicker("todate", $thedate, "to",true); 
     294        $theform->addField($theinput); 
     295 
     296        $theform->jsMerge(); 
     297        //============================================================== 
     298        //End Form Elements 
     299 
     300        include("header.php"); 
     301        ?> 
     302        <form action="<?php echo str_replace("&", "&amp;", $_SERVER["REQUEST_URI"]); ?>" method="post" name="totals" onsubmit="return validateForm(this)"> 
     303 
     304            <div class="bodyline" id="reportOptions"> 
     305 
     306                <h1 id="topTitle"><span>Client Purchase History Options</span></h1> 
     307 
     308                <fieldset> 
     309                    <legend>time frame</legend> 
     310 
     311                    <p id="fromP"><?php $theform->showField("fromdate");?></p> 
     312 
     313                    <p><?php $theform->showField("todate");?></p> 
     314                </fieldset> 
     315 
     316                <p> 
     317                    <label for="status">include products from...<br /></label> 
     318                    <select id="status" name="status"> 
     319                        <option value="Orders and Invoices" selected="selected">Orders and Invoices</option> 
     320                        <option value="Invoices">Invoices</option> 
     321                        <option value="Orders">Orders</option> 
     322                    </select> 
     323                </p> 
     324 
     325                <div align="right"> 
     326                    <input name="command" type="submit" class="Buttons" id="print" value="print" /> 
     327                    <input name="cancel" type="button" class="Buttons" id="cancel" value="cancel" onclick="window.close();" /> 
     328                </div> 
     329            </div> 
     330        </form> 
     331 
     332        <?php 
     333        include("footer.php"); 
     334 
     335    }//end function displayOptions 
     336 
     337}//end class  purchaseHistoryReport 
     338 
     339 
     340/** 
     341 * PROCESSING 
     342 * ============================================================================= 
     343 */ 
     344if(!isset($noOutput)){ 
     345 
     346    //IE needs caching to be set to private in order to display PDFS 
     347    session_cache_limiter('private'); 
     348 
     349    require_once("../../../include/session.php"); 
     350 
     351    checkForReportArguments(); 
     352 
     353    $report = new purchaseHistoryReport($db, $_GET["rid"], $_GET["tid"]); 
     354 
     355    if(!isset($_POST["command"]) && !isset($_GET["status"])) 
     356        $report->displayOptions(); 
     357    else{ 
     358 
     359        if(isset($_GET["status"])){ 
     360 
     361            $_POST["status"] = $_GET["status"]; 
     362            $_POST["fromdate"] = $_GET["fromdate"]; 
     363            $_POST["todate"] = $_GET["todate"]; 
     364 
     365        }//endif 
     366 
     367        //need to set post variables here 
     368 
     369        $report->setupFromPrintScreen(); 
     370        $report->initialize($_POST); 
     371        $report->generate(); 
     372        $report->output(); 
     373 
     374    }//endif 
     375 
     376 
     377}//end if 
     378 
     379/** 
     380 * When adding a new report record, the add/edit needs to know what the class 
     381 * name is so that it can instantiate it, and grab it's default settings. 
     382 */ 
     383if(isset($addingReportRecord)) 
     384    $reportClass ="purchaseHistoryReport"; 
  • trunk/phpbms/modules/bms/report/incoming_cashflow.php

    r611 r693  
    3838*/ 
    3939 
    40 require("../../../include/session.php"); 
    41  
    42 class totalReport{ 
     40if(!class_exists("phpbmsReport")) 
     41    require("../../../report/report_class.php"); 
     42 
     43class totalReport extends phpbmsReport{ 
    4344 
    4445        var $selectcolumns; 
    4546        var $tableClause = array(); 
    46         var $whereClause = array(); 
     47        var $whereClauses = array(); 
    4748        var $group = ""; 
    4849        var $showItems = false; 
     
    5152        var $toDate; 
    5253 
    53         function totalReport($db,$variables = NULL){ 
    54                 $this->db = $db; 
    55  
    56                 // first we define the available groups 
    57                 $this->addGroup("Year","YEAR(docdate)"); //0 
    58                 $this->addGroup("Quarter","QUARTER(docdate)"); //1 
    59                 $this->addGroup("Month","DATE_FORMAT(docdate, '%m - %b')"); //2 
    60                 $this->addGroup("Week","WEEK(docdate)"); //3 
    61                 $this->addGroup("Payment Method","paymentmethods.name"); //4 
    62                 $this->addGroup("Document Type","doctype"); //5 
    63  
    64  
    65                 //next we do the columns 
    66                 $this->addColumn("Record Count","COUNT(id)");//0 
    67                 $this->addColumn("Total","SUM(doctotal)","currency");//1 
    68  
    69  
    70                 if($variables){ 
    71  
    72                         $this->selectcolumns = $this->columns; 
    73  
    74                         $this->fromDate = $variables["fromdate"]; 
    75                         $this->toDate = $variables["todate"]; 
    76  
    77                         $this->tableClause["invoices"] = "(invoices INNER JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid)"; 
    78                         $this->tableClause["receipts"] = "(receipts INNER JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid)"; 
    79  
    80                         if($variables["groupings"] !== ""){ 
    81  
    82                                 $this->group = explode("::",$variables["groupings"]); 
    83                                 $this->group = array_reverse($this->group); 
    84  
    85                         } else 
    86                                 $this->group = array(); 
    87  
    88                         foreach($this->group as $grp){ 
    89  
    90                                 if($this->groupings[$grp]["table"]){ 
    91  
    92                                         foreach($this->tableClause as $key => $value); 
    93                                             $this->tableClause[$key]="(".$this->tableClause[$key]." ".$this->groupings[$grp]["table"].")"; 
    94  
    95                                 }//endif 
    96  
    97                         }//endforeach 
    98  
    99 //                      $this->whereclause = $_SESSION["printing"]["whereclause"]; 
    100 //                      if($this->whereclause=="") $this->whereclause="WHERE invoices.id!=-1"; 
    101                         $this->whereClause["invoices"] = " 
    102                             WHERE 
    103                                 (invoices.type = 'Invoice' 
    104                                 AND paymentmethods.type != 'receivable' 
    105                                 AND invoicedate >= '".sqlDateFromString($variables["fromdate"])."' 
    106                                 AND invoicedate <= '".sqlDateFromString($variables["todate"])."') 
    107                             "; 
    108  
    109                         $this->whereClause["receipts"] = " 
    110                             WHERE 
    111                                 (receipts.posted = 1 
    112                                 AND receiptdate >= '".sqlDateFromString($variables["fromdate"])."' 
    113                                 AND receiptdate <= '".sqlDateFromString($variables["todate"])."') 
    114                             "; 
    115  
    116                         $this->showItems = isset($variables["showitems"]); 
    117  
    118                 }// endif 
     54 
     55        function totalReport($db, $reportUUID, $tabledefUUID){ 
     56 
     57            $this->db = $db; 
     58 
     59            parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     60 
     61            // first we define the available groups 
     62            $this->addGroup("Year","YEAR(docdate)"); //0 
     63            $this->addGroup("Quarter","QUARTER(docdate)"); //1 
     64            $this->addGroup("Month","DATE_FORMAT(docdate, '%m - %b')"); //2 
     65            $this->addGroup("Week","WEEK(docdate)"); //3 
     66            $this->addGroup("Payment Method","paymentmethods.name"); //4 
     67            $this->addGroup("Document Type","doctype"); //5 
     68 
     69            //next we do the columns 
     70            $this->addColumn("Record Count","COUNT(id)");//0 
     71            $this->addColumn("Total","SUM(doctotal)","currency");//1 
     72 
     73            $this->tableClause["invoices"] = "(invoices INNER JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid)"; 
     74            $this->tableClause["receipts"] = "(receipts INNER JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid)"; 
     75 
    11976        }//end method 
     77 
     78 
     79        function processFromPost($variables){ 
     80 
     81            $this->selectcolumns = $this->columns; 
     82 
     83            $this->fromDate = $variables["fromdate"]; 
     84            $this->toDate = $variables["todate"]; 
     85 
     86            if($variables["groupings"] !== ""){ 
     87 
     88                $this->group = explode("::",$variables["groupings"]); 
     89                $this->group = array_reverse($this->group); 
     90 
     91            } else 
     92                $this->group = array(); 
     93 
     94            foreach($this->group as $grp){ 
     95 
     96                if($this->groupings[$grp]["table"]){ 
     97 
     98                    foreach($this->tableClause as $key => $value); 
     99                        $this->tableClause[$key] = "(".$this->tableClause[$key]." ".$this->groupings[$grp]["table"].")"; 
     100 
     101                }//endif 
     102 
     103            }//endforeach 
     104 
     105            $this->whereClauses["invoices"] = " 
     106                WHERE 
     107                    (invoices.type = 'Invoice' 
     108                    AND paymentmethods.type != 'receivable' 
     109                    AND invoicedate >= '".sqlDateFromString($variables["fromdate"])."' 
     110                    AND invoicedate <= '".sqlDateFromString($variables["todate"])."') 
     111                "; 
     112 
     113            $this->whereClauses["receipts"] = " 
     114                WHERE 
     115                    (receipts.posted = 1 
     116                    AND receiptdate >= '".sqlDateFromString($variables["fromdate"])."' 
     117                    AND receiptdate <= '".sqlDateFromString($variables["todate"])."') 
     118                "; 
     119 
     120            $this->showItems = isset($variables["showitems"]); 
     121 
     122        }//end function processFromPost 
     123 
     124 
     125        function processFromSettings(){ 
     126 
     127            $variables["fromdate"] = $this->settings["fromDate"]; 
     128            $variables["todate"] = $this->settings["toDate"]; 
     129 
     130            $variables["groupings"] = ""; 
     131            foreach($this->settings as $key=>$value) 
     132                if(strpos($key, "group") === 0) 
     133                    $variables["groupings"] .= "::".$value; 
     134 
     135            if($variables["groupings"]) 
     136                $variables["groupings"] = substr($variables["groupings"], 2); 
     137 
     138            $variables["showitems"] = isset($this->settings["showItems"]); 
     139 
     140            $this->processFromPost($variables); 
     141 
     142        }//end function processFromSettings 
    120143 
    121144 
     
    206229                $querystatement = "(SELECT"; 
    207230                $querystatement .= $this->generateColumns("invoices").", COUNT(invoices.id) AS thecount "; 
    208                 $querystatement .= "FROM ".$this->tableClause["invoices"]." ".$this->whereClause["invoices"].")"; 
     231                $querystatement .= "FROM ".$this->tableClause["invoices"]." ".$this->whereClauses["invoices"].")"; 
    209232                $querystatement .= " UNION "; 
    210233                $querystatement .= "(SELECT"; 
    211234                $querystatement .= $this->generateColumns("receipts").", COUNT(receipts.id) AS thecount "; 
    212                 $querystatement .= "FROM ".$this->tableClause["receipts"]." ".$this->whereClause["receipts"].")"; 
     235                $querystatement .= "FROM ".$this->tableClause["receipts"]." ".$this->whereClauses["receipts"].")"; 
    213236 
    214237 
     
    257280                        $querystatement .= $this->generateColumns("invoices").", COUNT(invoices.id) AS `thecount` "; 
    258281                        $querystatement .= ", ".$this->typeSubstitute($this->groupings[$groupby]["field"], "invoices")." AS `thegroup`"; 
    259                         $querystatement .= "FROM ".$this->tableClause["invoices"]." ".$this->whereClause["invoices"].$this->typeSubstitute($where, "invoices"); 
     282                        $querystatement .= "FROM ".$this->tableClause["invoices"]." ".$this->whereClauses["invoices"].$this->typeSubstitute($where, "invoices"); 
    260283                        $querystatement .= " GROUP BY `thegroup`)"; 
    261284                        $querystatement .= " UNION "; 
     
    263286                        $querystatement .= $this->generateColumns("receipts").", COUNT(receipts.id) AS thecount "; 
    264287                        $querystatement .= ", ".$this->typeSubstitute($this->groupings[$groupby]["field"], "receipts")." AS `thegroup`"; 
    265                         $querystatement .= "FROM ".$this->tableClause["receipts"]." ".$this->whereClause["receipts"].$this->typeSubstitute($where, "receipts"); 
     288                        $querystatement .= "FROM ".$this->tableClause["receipts"]." ".$this->whereClauses["receipts"].$this->typeSubstitute($where, "receipts"); 
    266289                        $querystatement .= " GROUP BY `thegroup`)"; 
    267290                        $querystatement .= " ORDER BY `thegroup`"; 
     
    421444                    FROM 
    422445                        (".$this->tableClause["invoices"].") INNER JOIN clients ON invoices.clientid = clients.uuid 
    423                         ".$this->whereClause["invoices"].$this->typeSubstitute($where, "invoices")." 
     446                        ".$this->whereClauses["invoices"].$this->typeSubstitute($where, "invoices")." 
    424447                    GROUP BY `theid`) 
    425448                    UNION 
     
    431454                    FROM 
    432455                        (".$this->tableClause["receipts"].") INNER JOIN clients ON receipts.clientid = clients.uuid 
    433                         ".$this->whereClause["receipts"].$this->typeSubstitute($where, "receipts")." 
     456                        ".$this->whereClauses["receipts"].$this->typeSubstitute($where, "receipts")." 
    434457                    GROUP BY `theid`) 
    435458                    ORDER BY `docdate`"; 
     
    464487        function showReport(){ 
    465488 
    466             $pageTitle = "Incoming Cash Flow"; 
     489            if(!isset($this->settings["reportTitle"])) 
     490                $this->settings["reportTitle"] = "Incoming Cash Flow"; 
    467491 
    468492 
     
    477501<body> 
    478502        <div id="toprint"> 
    479                 <h1><span><?php echo $pageTitle?></span></h1> 
     503                <h1><span><?php echo formatVariable($this->settings["reportTitle"]); ?></span></h1> 
    480504                <h2>Dates: <?php echo $this->fromDate ?> - <?php echo $this->toDate ?></h2> 
    481505 
     
    582606}//endclass 
    583607 
    584 // Processing =================================================================================================================== 
    585 if(!isset($dontProcess)){ 
    586         if(isset($_POST["fromdate"])){ 
    587                 $myreport= new totalReport($db,$_POST); 
    588                 $myreport->showReport(); 
    589         } else { 
    590                 $myreport = new totalReport($db); 
    591                 $myreport->showSelectScreen(); 
    592         } 
    593 }?> 
     608 
     609/** 
     610 * PROCESSING 
     611 * ============================================================================= 
     612 */ 
     613if(!isset($noOutput)){ 
     614 
     615    //IE needs caching to be set to private in order to display PDFS 
     616    session_cache_limiter('private'); 
     617 
     618    //set encoding to latin1 (fpdf doesnt like utf8) 
     619    $sqlEncoding = "latin1"; 
     620    require_once("../../../include/session.php"); 
     621 
     622    checkForReportArguments(); 
     623 
     624    $report = new totalReport($db, $_GET["rid"], $_GET["tid"]); 
     625 
     626    if(isset($_POST["fromdate"])){ 
     627 
     628        $report->processFromPost($_POST); 
     629        $report->showReport(); 
     630 
     631    } elseif(isset($report->settings["fromdate"]) && isset($report->settings["todate"]) && isset($report->settings["groupings"])){ 
     632 
     633        $report->processFromSettings(); 
     634        $report->showReport(); 
     635 
     636    }else 
     637        $report->showSelectScreen(); 
     638 
     639}//end if 
     640 
     641/** 
     642 * When adding a new report record, the add/edit needs to know what the class 
     643 * name is so that it can instantiate it, and grab it's default settings. 
     644 */ 
     645if(isset($addingReportRecord)) 
     646    $reportClass ="totalReport"; 
     647 
     648?> 
  • trunk/phpbms/modules/bms/report/invoices_pdfinvoice.php

    r673 r693  
    3838*/ 
    3939 
    40 //PROCESSING 
    41 //============================================================================= 
     40/** 
     41 * PROCESSING 
     42 * ============================================================================= 
     43 */ 
    4244if(!isset($noOutput)){ 
    4345 
    44         //IE needs caching to be set to private in order to display PDFS 
    45         session_cache_limiter('private'); 
     46    //IE needs caching to be set to private in order to display PDFS 
     47    session_cache_limiter('private'); 
    4648 
    47         //set encoding to latin1 (fpdf doesnt like utf8) 
    48         $sqlEncoding = "latin1"; 
    49         require_once("../../../include/session.php"); 
     49    //set encoding to latin1 (fpdf doesnt like utf8) 
     50    $sqlEncoding = "latin1"; 
     51    require_once("../../../include/session.php"); 
    5052 
    51         include("modules/bms/report/invoices_pdf_class.php"); 
     53    include("modules/bms/report/invoices_pdf_class.php"); 
    5254 
    53         $report = new invoicePDF($db, 'P', 'in', 'Letter'); 
    54         $report->setupFromPrintScreen(); 
    55         $report->generate(); 
    56          
    57         $filename = "Invoice"; 
    58         if($report->count === 1){ 
    59                  
    60                 if($report->invoicerecord["company"]) 
    61                         $filename .= "_".$report->invoicerecord["company"]; 
    62                  
    63                 $filename .= "_".$report->invoicerecord["id"]; 
    64                  
    65         }elseif((int)$report->count) 
    66                 $filename .= "_Multiple"; 
    67          
    68         $filename .= ".pdf"; 
    69         $report->output('screen', $filename); 
     55    checkForReportArguments(); 
     56 
     57    $report = new invoicePDF($db, $_GET["rid"], $_GET["tid"], 'P', 'in', 'Letter'); 
     58    $report->setupFromPrintScreen(); 
     59    $report->generate(); 
     60 
     61    $filename = "Invoice"; 
     62    if($report->count === 1){ 
     63 
     64        if($report->invoicerecord["company"]) 
     65            $filename .= "_".$report->invoicerecord["company"]; 
     66 
     67        $filename .= "_".$report->invoicerecord["id"]; 
     68 
     69    }elseif((int)$report->count) 
     70        $filename .= "_Multiple"; 
     71 
     72    $filename .= ".pdf"; 
     73 
     74    $report->output('screen', $filename); 
    7075 
    7176}//end if 
    7277 
     78 
     79/** 
     80 * When adding a new report record, the add/edit needs to know what the class 
     81 * name is so that it can instantiate it, and grab it's default settings. 
     82 */ 
     83if(isset($addingReportRecord)){ 
     84 
     85    include("modules/bms/report/invoices_pdf_class.php"); 
     86    $reportClass = "invoicePDF"; 
     87 
     88}//endif 
    7389?> 
  • trunk/phpbms/modules/bms/report/invoices_pdfpackinglist.php

    r673 r693  
    3838*/ 
    3939 
    40         if(!isset($_SESSION["userinfo"]["id"])){ 
    41  
    42                 //IE needs caching to be set to private in order to display PDFS 
    43                 session_cache_limiter('private'); 
    44  
    45                 //set encoding to latin1 (fpdf doesnt like utf8) 
    46                 $sqlEncoding = "latin1"; 
    47                 require_once("../../../include/session.php"); 
    48  
    49         }//end if 
    50  
    51         if(!class_exists("invoicePDF")) 
    52                 include("invoices_pdf_class.php"); 
    53  
    54         class  packinglistPDF extends invoicePDF{ 
    55  
    56                 var $title = "Packing List"; 
    57                 var $showShipNameInShipTo = false; 
    58  
    59                 function packinglistPDF($db, $orientation='P', $unit='mm', $format='Letter'){ 
    60  
    61                         $this->invoicePDF($db, $orientation, $unit, $format); 
    62  
    63                 }//end method 
    64  
    65  
    66                 function initialize(){ 
    67                         //This function will set column headings, sizes and formatting 
    68  
    69                         $pdf = &$this->pdf; 
    70  
    71                         $topinfo = array(); 
    72                         $topinfo[] = new pdfColumn("Order ID", "id", 0.75); 
    73                         $topinfo[] = new pdfColumn("Order Date", "orderdate", 1, "date"); 
    74                         $topinfo[] = new pdfColumn("Client PO", "ponumber", 0); 
    75  
    76                         $size = 0; 
    77                         foreach($topinfo as $column) 
    78                                 $size += $column->size; 
    79  
    80                         $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    81  
    82                         $this->topinfo = $topinfo; 
    83  
    84                         $lineitems = array(); 
    85                         $lineitems[] = new pdfColumn("Product / (Part Number)", "parts", 0); 
    86                         $lineitems[] = new pdfColumn("Prepackaged", "isprepackaged", 0.75, "boolean", "C"); 
    87                         $lineitems[] = new pdfColumn("Oversized", "isoversized", 0.75, "boolean", "C"); 
    88                         $lineitems[] = new pdfColumn("Unit Weight", "unitweight", 0.75, "real", "R"); 
    89                         $lineitems[] = new pdfColumn("Qty", "quantity", 0.5, "real","R"); 
    90                         $lineitems[] = new pdfColumn("Weight Ext.", "extended", 0.75, "real", "R"); 
    91  
    92                         $size = 0; 
    93                         foreach($lineitems as $column) 
    94                                 $size += $column->size; 
    95  
    96                         $lineitems[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    97  
    98                         $this->lineitems = $lineitems; 
    99  
    100                         $totalsinfo = array(); 
    101                         $totalsinfo[] = new pdfColumn("Shipping Method", "shippingname", 0); 
    102                         $totalsinfo[] = new pdfColumn("Estimated Boxes", "estimatedboxes", 1, NULL, "C"); 
    103                         $totalsinfo[] = new pdfColumn("Total Weight", "totalweight", 1, "real", "R"); 
    104                         $totalsinfo[] = new pdfColumn("Shipping", "shipping", 1, "currency", "R"); 
    105  
    106                         $size = 0; 
    107                         foreach($totalsinfo as $column) 
    108                                 $size += $column->size; 
    109  
    110                         $totalsinfo[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    111  
    112                         $this->totalsinfo = $totalsinfo; 
    113  
    114                 }//end method 
    115  
    116  
    117                 function _addNotes(){ 
    118  
    119                         $pdf = &$this->pdf; 
    120  
    121                         $height = 1; 
    122                         $nextPos = $pdf->GetY() + $height + 0.125; 
    123  
    124                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    125                         $pdf->setStyle("header"); 
    126                         $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Special Instructions", 1, 2, "L", 1); 
    127  
    128                         $pdf->setStyle("normal"); 
    129                         $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
    130                         $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["specialinstructions"]); 
    131  
    132                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    133  
    134                 }//end method 
    135  
    136  
    137                 function _getLineItems(){ 
    138  
    139                         $querystatement = " 
    140                         SELECT 
    141                                 lineitems.*, 
    142                                 lineitems.quantity*lineitems.unitweight as extended, 
    143                                 products.partname, 
    144                                 products.partnumber, 
    145                                 products.isoversized, 
    146                                 products.isprepackaged, 
    147                                 products.packagesperitem 
    148                         FROM 
    149                                 lineitems LEFT JOIN products ON lineitems.productid = products.id 
    150                         WHERE 
    151                                 lineitems.invoiceid =".((int) $this->invoicerecord["id"])." 
    152                         ORDER BY 
    153                                 displayorder"; 
    154  
    155                         $queryresult = $this->db->query($querystatement); 
    156  
    157                         //determine estimated total boxes 
    158                         $this->invoicerecord["estimatedboxes"] = 0; 
    159                         while($therecord = $this->db->fetchArray($queryresult)){ 
    160  
    161                                 if($therecord["isprepackaged"]) 
    162                                         $this->invoicerecord["estimatedboxes"] += $therecord["quantity"]; 
    163                                 else 
    164                                         $this->invoicerecord["estimatedboxes"] += $therecord["quantity"] * $therecord["packagesperitem"]; 
    165  
    166                         }//endwhile 
    167  
    168                         $this->db->seek($queryresult, 0); 
    169  
    170                         return $queryresult; 
    171  
    172                 }//end method 
    173  
    174                 function _addTotals(){ 
    175  
    176                         $pdf = &$this->pdf; 
    177  
    178                         $height = .5; 
    179                         $nextPos = $pdf->GetY() + $height + 0.125; 
    180  
    181                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    182  
    183                         $pdf->setStyle("header"); 
    184                         foreach($this->totalsinfo as $column) 
    185                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    186  
    187                         $pdf->setStyle("normal"); 
    188                         $pdf->SetFont("Arial", "B", 10); 
    189                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
    190  
    191                         foreach($this->totalsinfo as $column){ 
    192  
    193                                 if($column->format != "") 
    194                                         $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
    195                                 else 
    196                                         $value = $this->invoicerecord[$column->fieldname]; 
    197  
    198                                 $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    199  
    200                         }//end foreach 
    201  
    202                 }//end method 
    203  
    204         }//end class 
    205  
    206  
    207         //PROCESSING 
    208         //============================================================================= 
    209         if(!isset($noOutput)){ 
    210  
    211                 $report = new packinglistPDF($db, 'P', 'in', 'Letter'); 
    212  
    213                 $report->setupFromPrintScreen(); 
    214                 $report->generate(); 
    215                 $filename = "Packing_List"; 
    216                  
    217                 if($report->count === 1){ 
    218                          
    219                         if($report->invoicerecord["company"]) 
    220                                 $filename .= "_".$report->invoicerecord["company"]; 
    221                          
    222                         $filename .= "_".$report->invoicerecord["id"]; 
    223                          
    224                 }elseif((int)$report->count) 
    225                         $filename .= "_Multiple"; 
    226                  
    227                 $report->output('screen', $filename); 
    228  
    229         }//end if 
     40if(!class_exists("invoicePDF")) 
     41    include("invoices_pdf_class.php"); 
     42 
     43class  packinglistPDF extends invoicePDF{ 
     44 
     45    var $showShipNameInShipTo = false; 
     46 
     47    function packinglistPDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ 
     48 
     49            $this->invoicePDF($db, $reportUUID, $tabledefUUID, $orientation, $unit, $format); 
     50 
     51    }//end method 
     52 
     53 
     54    /** 
     55     * function checkForDefaultSettings 
     56     * 
     57     * Checks to make sure loaded report Settings exist and are correct 
     58     */ 
     59    function checkForDefaultSettings(){ 
     60 
     61        if(!isset($this->settings["reportTitle"])) 
     62            $this->settings["reportTitle"] = "Packing List"; 
     63 
     64        parent::checkForDefaultSettings(); 
     65 
     66    }//end function checkForDefaultSettings 
     67 
     68 
     69    function initialize(){ 
     70            //This function will set column headings, sizes and formatting 
     71 
     72            $pdf = &$this->pdf; 
     73 
     74            $topinfo = array(); 
     75            $topinfo[] = new pdfColumn("Order ID", "id", 0.75); 
     76            $topinfo[] = new pdfColumn("Order Date", "orderdate", 1, "date"); 
     77            $topinfo[] = new pdfColumn("Client PO", "ponumber", 0); 
     78 
     79            $size = 0; 
     80            foreach($topinfo as $column) 
     81                    $size += $column->size; 
     82 
     83            $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     84 
     85            $this->topinfo = $topinfo; 
     86 
     87            $lineitems = array(); 
     88            $lineitems[] = new pdfColumn("Product / (Part Number)", "parts", 0); 
     89            $lineitems[] = new pdfColumn("Prepackaged", "isprepackaged", 0.75, "boolean", "C"); 
     90            $lineitems[] = new pdfColumn("Oversized", "isoversized", 0.75, "boolean", "C"); 
     91            $lineitems[] = new pdfColumn("Unit Weight", "unitweight", 0.75, "real", "R"); 
     92            $lineitems[] = new pdfColumn("Qty", "quantity", 0.5, "real","R"); 
     93            $lineitems[] = new pdfColumn("Weight Ext.", "extended", 0.75, "real", "R"); 
     94 
     95            $size = 0; 
     96            foreach($lineitems as $column) 
     97                    $size += $column->size; 
     98 
     99            $lineitems[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     100 
     101            $this->lineitems = $lineitems; 
     102 
     103            $totalsinfo = array(); 
     104            $totalsinfo[] = new pdfColumn("Shipping Method", "shippingname", 0); 
     105            $totalsinfo[] = new pdfColumn("Estimated Boxes", "estimatedboxes", 1, NULL, "C"); 
     106            $totalsinfo[] = new pdfColumn("Total Weight", "totalweight", 1, "real", "R"); 
     107            $totalsinfo[] = new pdfColumn("Shipping", "shipping", 1, "currency", "R"); 
     108 
     109            $size = 0; 
     110            foreach($totalsinfo as $column) 
     111                    $size += $column->size; 
     112 
     113            $totalsinfo[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     114 
     115            $this->totalsinfo = $totalsinfo; 
     116 
     117    }//end method 
     118 
     119 
     120    function _addNotes(){ 
     121 
     122            $pdf = &$this->pdf; 
     123 
     124            $height = 1; 
     125            $nextPos = $pdf->GetY() + $height + 0.125; 
     126 
     127            if(!$this->settings["templateFormatting"]){ 
     128 
     129                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     130                $pdf->setStyle("header"); 
     131                $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Special Instructions", 1, 2, "L", 1); 
     132 
     133            }//endif 
     134 
     135            $pdf->setStyle("normal"); 
     136            $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
     137            $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["specialinstructions"]); 
     138 
     139            $pdf->SetXY($pdf->leftmargin, $nextPos); 
     140 
     141    }//end method 
     142 
     143 
     144    function _getLineItems(){ 
     145 
     146            $querystatement = " 
     147            SELECT 
     148                    lineitems.*, 
     149                    lineitems.quantity*lineitems.unitweight as extended, 
     150                    products.partname, 
     151                    products.partnumber, 
     152                    products.isoversized, 
     153                    products.isprepackaged, 
     154                    products.packagesperitem 
     155            FROM 
     156                    lineitems LEFT JOIN products ON lineitems.productid = products.id 
     157            WHERE 
     158                    lineitems.invoiceid =".((int) $this->invoicerecord["id"])." 
     159            ORDER BY 
     160                    displayorder"; 
     161 
     162            $queryresult = $this->db->query($querystatement); 
     163 
     164            //determine estimated total boxes 
     165            $this->invoicerecord["estimatedboxes"] = 0; 
     166            while($therecord = $this->db->fetchArray($queryresult)){ 
     167 
     168                    if($therecord["isprepackaged"]) 
     169                            $this->invoicerecord["estimatedboxes"] += $therecord["quantity"]; 
     170                    else 
     171                            $this->invoicerecord["estimatedboxes"] += $therecord["quantity"] * $therecord["packagesperitem"]; 
     172 
     173            }//endwhile 
     174 
     175            $this->db->seek($queryresult, 0); 
     176 
     177            return $queryresult; 
     178 
     179    }//end method 
     180 
     181 
     182    function _addTotals(){ 
     183 
     184            $pdf = &$this->pdf; 
     185 
     186            $height = .5; 
     187            $nextPos = $pdf->GetY() + $height + 0.125; 
     188 
     189            if(!$this->settings["templateFormatting"]){ 
     190 
     191                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     192 
     193                $pdf->setStyle("header"); 
     194                foreach($this->totalsinfo as $column) 
     195                    $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     196 
     197            } else 
     198                $pdf->SetY($pdf->GetY() + 0.18); 
     199 
     200            $pdf->setStyle("normal"); 
     201            $pdf->SetFont("Arial", "B", 10); 
     202            $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
     203 
     204            foreach($this->totalsinfo as $column){ 
     205 
     206                    if($column->format != "") 
     207                            $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
     208                    else 
     209                            $value = $this->invoicerecord[$column->fieldname]; 
     210 
     211                    $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     212 
     213            }//end foreach 
     214 
     215    }//end method 
     216 
     217 
     218    /** 
     219     * function addingRecordDefaultSettings 
     220     * 
     221     * Creates an array of settings associative arrays for use by the system when 
     222     * a new report record is added that references the file containing this class 
     223     * 
     224     * @retrun array of settings. Each setting should itself be 
     225     * an associative array containing the following 
     226     * name: name of the setting 
     227     * defaultvalue: default value for setting 
     228     * type: (string, int, real, bool) type for value of setting 
     229     * required: (0,1) whether the setting is required or not 
     230     * description: brief description for what this setting is used for. 
     231     */ 
     232    function addingRecordDefaultSettings(){ 
     233 
     234        $settings = parent::addingRecordDefaultSettings(); 
     235 
     236        for($i=0; $i< count($settings); $i++){ 
     237 
     238            switch($settings[$i]["name"]){ 
     239 
     240                case "reportTitle": 
     241                    $settings[$i]["defaultValue"] = "Packing List"; 
     242 
     243            }//endswitch 
     244 
     245        }//end foreach 
     246 
     247        return $settings; 
     248 
     249    }//endfunction addingRecordDefaultSettings 
     250 
     251}//end class 
     252 
     253 
     254/** 
     255 * PROCESSING 
     256 * ============================================================================= 
     257 */ 
     258if(!isset($noOutput)){ 
     259 
     260    //IE needs caching to be set to private in order to display PDFS 
     261    session_cache_limiter('private'); 
     262 
     263    //set encoding to latin1 (fpdf doesnt like utf8) 
     264    $sqlEncoding = "latin1"; 
     265    require_once("../../../include/session.php"); 
     266 
     267    checkForReportArguments(); 
     268 
     269    $report = new packinglistPDF($db, $_GET["rid"], $_GET["tid"], 'P', 'in', 'Letter'); 
     270 
     271    $report->setupFromPrintScreen(); 
     272    $report->generate(); 
     273    $filename = "Packing_List"; 
     274 
     275    if($report->count === 1){ 
     276 
     277        if($report->invoicerecord["company"]) 
     278            $filename .= "_".$report->invoicerecord["company"]; 
     279 
     280        $filename .= "_".$report->invoicerecord["id"]; 
     281 
     282    }elseif((int)$report->count) 
     283        $filename .= "_Multiple"; 
     284 
     285    $filename .=".pdf"; 
     286 
     287    $report->output('screen', $filename); 
     288 
     289}//end if 
     290 
     291 
     292/** 
     293 * When adding a new report record, the add/edit needs to know what the class 
     294 * name is so that it can instantiate it, and grab it's default settings. 
     295 */ 
     296if(isset($addingReportRecord)) 
     297    $reportClass ="packinglistPDF"; 
    230298?> 
  • trunk/phpbms/modules/bms/report/invoices_pdfquote.php

    r673 r693  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39 if(!isset($_SESSION["userinfo"]["id"])){ 
    40  
    41         //IE needs caching to be set to private in order to display PDFS 
    42         session_cache_limiter('private'); 
    43  
    44         //set encoding to latin1 (fpdf doesnt like utf8) 
    45         $sqlEncoding = "latin1"; 
    46         require_once("../../../include/session.php"); 
    47  
    48 }//end if 
    49  
    5039if(!class_exists("invoicePDF")) 
    51         include("invoices_pdf_class.php"); 
     40    include("invoices_pdf_class.php"); 
    5241 
    5342class  quotePDF extends invoicePDF{ 
    5443 
    55         var $title = "Quote"; 
     44    function quotePDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ 
    5645 
    57         function quotePDF($db, $orientation='P', $unit='mm', $format='Letter'){ 
     46        $this->invoicePDF($db, $reportUUID, $tabledefUUID, $orientation, $unit, $format); 
    5847 
    59                 $this->invoicePDF($db, $orientation, $unit, $format); 
     48    }//end method 
    6049 
    61         }//end method 
    6250 
    63         function initialize(){ 
    64                 parent::initialize(); 
     51    /** 
     52     * function checkForDefaultSettings 
     53     * 
     54     * Checks to make sure loaded report Settings exist and are correct 
     55     */ 
     56    function checkForDefaultSettings(){ 
    6557 
    66                 unset($this->totalsinfo[5]); 
     58        if(!isset($this->settings["reportTitle"])) 
     59            $this->settings["reportTitle"] = "Quote"; 
    6760 
    68         }//end method 
     61        parent::checkForDefaultSettings(); 
     62 
     63    }//end function checkForDefaultSettings 
     64 
     65 
     66    function initialize(){ 
     67 
     68        parent::initialize(); 
     69 
     70        unset($this->totalsinfo[5]); 
     71 
     72    }//end method 
     73 
     74 
     75    /** 
     76     * function addingRecordDefaultSettings 
     77     * 
     78     * Creates an array of settings associative arrays for use by the system when 
     79     * a new report record is added that references the file containing this class 
     80     * 
     81     * @retrun array of settings. Each setting should itself be 
     82     * an associative array containing the following 
     83     * name: name of the setting 
     84     * defaultvalue: default value for setting 
     85     * type: (string, int, real, bool) type for value of setting 
     86     * required: (0,1) whether the setting is required or not 
     87     * description: brief description for what this setting is used for. 
     88     */ 
     89    function addingRecordDefaultSettings(){ 
     90 
     91        $settings = parent::addingRecordDefaultSettings(); 
     92 
     93        for($i=0; $i< count($settings); $i++){ 
     94 
     95            switch($settings[$i]["name"]){ 
     96 
     97                case "reportTitle": 
     98                    $settings[$i]["defaultValue"] = "Quote"; 
     99 
     100            }//endswitch 
     101 
     102        }//end foreach 
     103 
     104        return $settings; 
     105 
     106    }//endfunction addingRecordDefaultSettings 
    69107 
    70108}//end class 
    71109 
    72 //PROCESSING 
    73 //============================================================================= 
     110 
     111/** 
     112 * PROCESSING 
     113 * ============================================================================= 
     114 */ 
    74115if(!isset($noOutput)){ 
    75116 
    76         $report = new quotePDF($db, 'P', 'in', 'Letter'); 
    77         $report->showShipNameInShipTo = false; 
     117    //IE needs caching to be set to private in order to display PDFS 
     118    session_cache_limiter('private'); 
    78119 
    79         $report->setupFromPrintScreen(); 
    80         $report->generate(); 
    81          
    82         $filename = "Quote"; 
    83         if($report->count === 1){ 
    84                  
    85                 if($report->invoicerecord["company"]) 
    86                         $filename .= "_".$report->invoicerecord["company"]; 
    87                  
    88                 $filename .= "_".$report->invoicerecord["id"]; 
    89                  
    90         }elseif((int)$report->count) 
    91                 $filename .= "_Multiple"; 
    92          
    93         $filename .= ".pdf"; 
    94          
    95         $report->output('screen', $filename); 
     120    //set encoding to latin1 (fpdf doesnt like utf8) 
     121    $sqlEncoding = "latin1"; 
     122    require_once("../../../include/session.php"); 
     123 
     124    checkForReportArguments(); 
     125 
     126    $report = new quotePDF($db, $_GET["rid"], $_GET["tid"], 'P', 'in', 'Letter'); 
     127    $report->showShipNameInShipTo = false; 
     128 
     129    $report->setupFromPrintScreen(); 
     130    $report->generate(); 
     131 
     132    $filename = "Quote"; 
     133    if($report->count === 1){ 
     134 
     135        if($report->invoicerecord["company"]) 
     136            $filename .= "_".$report->invoicerecord["company"]; 
     137 
     138        $filename .= "_".$report->invoicerecord["id"]; 
     139 
     140    }elseif((int)$report->count) 
     141        $filename .= "_Multiple"; 
     142 
     143    $filename .= ".pdf"; 
     144 
     145    $report->output('screen', $filename); 
    96146 
    97147}//end if 
    98148 
    99149 
     150/** 
     151 * When adding a new report record, the add/edit needs to know what the class 
     152 * name is so that it can instantiate it, and grab it's default settings. 
     153 */ 
     154if(isset($addingReportRecord)) 
     155    $reportClass ="quotePDF"; 
    100156?> 
  • trunk/phpbms/modules/bms/report/invoices_pdfworkorder.php

    r673 r693  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39         if(!isset($_SESSION["userinfo"]["id"])){ 
    40  
    41                 //IE needs caching to be set to private in order to display PDFS 
    42                 session_cache_limiter('private'); 
    43  
    44                 //set encoding to latin1 (fpdf doesnt like utf8) 
    45                 $sqlEncoding = "latin1"; 
    46                 require_once("../../../include/session.php"); 
    47  
    48         }//end if 
    49  
    50         if(!class_exists("invoicePDF")) 
    51                 include("invoices_pdf_class.php"); 
    52  
    53         class  workorderPDF extends invoicePDF{ 
    54  
    55                 var $title = "Work Order"; 
    56                 var $lineitemBoxHeight = 3.75; 
    57  
    58                 function workorderPDF($db, $orientation='P', $unit='mm', $format='Letter'){ 
    59  
    60                         $this->invoicePDF($db, $orientation, $unit, $format); 
    61  
    62                 }//end method 
    63  
    64  
    65                 function _addNotes(){ 
    66  
    67                         $pdf = &$this->pdf; 
    68  
    69                         $height = 1; 
    70                         $nextPos = $pdf->GetY() + $height + 0.125; 
    71  
    72                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    73                         $pdf->setStyle("header"); 
    74                         $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Special Instructions", 1, 2, "L", 1); 
    75  
    76                         $pdf->setStyle("normal"); 
    77                         $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
    78                         $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["specialinstructions"]); 
    79  
    80                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    81  
    82                 }//end method 
    83  
    84                 function _addPaymentDetails(){ 
    85  
    86                         $pdf = &$this->pdf; 
    87  
    88                         $columns = array(); 
    89                         $columns[] = new pdfColumn("Payment Method", "paymentname", 0); 
    90  
    91                         switch($this->invoicerecord["paymenttype"]){ 
    92  
    93                                 case "draft": 
    94                                         $columns[0]->size = 1.5; 
    95                                         $columns[] = new pdfColumn("Check Number", "checkno", 1); 
    96                                         $columns[] = new pdfColumn("Bank Name", "bankname", 2); 
    97                                         break; 
    98  
    99                                 case "charge": 
    100                                         $columns[0]->size = 1.5; 
    101                                         $columns[] = new pdfColumn("Number", "ccnumber", 1.5); 
    102                                         $columns[] = new pdfColumn("Exp.", "ccexpiration", 1); 
    103                                         $columns[] = new pdfColumn("Verification/Pin", "ccverification", 1); 
    104                                         break; 
    105  
    106                         }//end switch 
    107  
    108                         $size = 0; 
    109                         foreach($columns as $column) 
    110                                 $size += $column->size; 
    111  
    112                         $i = count($columns) -1; 
    113  
    114                         $columns[$i]->size += $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    115  
    116                         $height = 0.5; 
    117                         $nextPos = $pdf->GetY() + $height + 0.125; 
    118  
    119                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    120  
    121                         $pdf->setStyle("header"); 
    122  
    123                         foreach($columns as $column) 
    124                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    125  
    126                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
    127  
    128                         $pdf->setStyle("normal"); 
    129                         $pdf->SetFont("Arial", "B", 10); 
    130                         foreach($columns as $column) 
    131                                 $pdf->Cell($column->size, 0.18, $this->invoicerecord[$column->fieldname], $pdf->borderDebug, 0, $column->align); 
    132  
    133                 }//end method 
    134  
    135         }//end class 
    136  
    137  
    138 //PROCESSING 
    139 //============================================================================= 
     39if(!class_exists("invoicePDF")) 
     40    include("invoices_pdf_class.php"); 
     41 
     42class  workorderPDF extends invoicePDF{ 
     43 
     44    var $lineitemBoxHeight = 3.75; 
     45 
     46 
     47    function workorderPDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ 
     48 
     49        $this->invoicePDF($db, $reportUUID, $tabledefUUID, $orientation, $unit, $format); 
     50 
     51    }//end method 
     52 
     53 
     54    /** 
     55     * function checkForDefaultSettings 
     56     * 
     57     * Checks to make sure loaded report Settings exist and are correct 
     58     */ 
     59    function checkForDefaultSettings(){ 
     60 
     61        if(!isset($this->settings["reportTitle"])) 
     62            $this->settings["reportTitle"] = "Work Order"; 
     63 
     64        parent::checkForDefaultSettings(); 
     65 
     66    }//end function checkForDefaultSettings 
     67 
     68 
     69    function _addNotes(){ 
     70 
     71            $pdf = &$this->pdf; 
     72 
     73            $height = 1; 
     74            $nextPos = $pdf->GetY() + $height + 0.125; 
     75 
     76            if(!$this->settings["templateFormatting"]){ 
     77 
     78                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     79                $pdf->setStyle("header"); 
     80                $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Special Instructions", 1, 2, "L", 1); 
     81 
     82            }else 
     83                $pdf->SetY($pdf->GetY() + 0.18); 
     84 
     85            $pdf->setStyle("normal"); 
     86            $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
     87            $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["specialinstructions"]); 
     88 
     89            $pdf->SetXY($pdf->leftmargin, $nextPos); 
     90 
     91    }//end method 
     92 
     93    function _addPaymentDetails(){ 
     94 
     95            $pdf = &$this->pdf; 
     96 
     97            $columns = array(); 
     98            $columns[] = new pdfColumn("Payment Method", "paymentname", 0); 
     99 
     100            switch($this->invoicerecord["paymenttype"]){ 
     101 
     102                    case "draft": 
     103                            $columns[0]->size = 1.5; 
     104                            $columns[] = new pdfColumn("Check Number", "checkno", 1); 
     105                            $columns[] = new pdfColumn("Bank Name", "bankname", 2); 
     106                            break; 
     107 
     108                    case "charge": 
     109                            $columns[0]->size = 1.5; 
     110                            $columns[] = new pdfColumn("Number", "ccnumber", 1.5); 
     111                            $columns[] = new pdfColumn("Exp.", "ccexpiration", 1); 
     112                            $columns[] = new pdfColumn("Verification/Pin", "ccverification", 1); 
     113                            break; 
     114 
     115            }//end switch 
     116 
     117            $size = 0; 
     118            foreach($columns as $column) 
     119                    $size += $column->size; 
     120 
     121            $i = count($columns) -1; 
     122 
     123            $columns[$i]->size += $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     124 
     125            $height = 0.5; 
     126            $nextPos = $pdf->GetY() + $height + 0.125; 
     127 
     128            if(!$this->settings["templateFormatting"]){ 
     129 
     130                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     131 
     132                $pdf->setStyle("header"); 
     133 
     134                foreach($columns as $column) 
     135                    $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     136 
     137            }//endif 
     138 
     139            $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
     140 
     141            $pdf->setStyle("normal"); 
     142            $pdf->SetFont("Arial", "B", 10); 
     143            foreach($columns as $column) 
     144                    $pdf->Cell($column->size, 0.18, $this->invoicerecord[$column->fieldname], $pdf->borderDebug, 0, $column->align); 
     145 
     146    }//end method 
     147 
     148    /** 
     149     * function addingRecordDefaultSettings 
     150     * 
     151     * Creates an array of settings associative arrays for use by the system when 
     152     * a new report record is added that references the file containing this class 
     153     * 
     154     * @retrun array of settings. Each setting should itself be 
     155     * an associative array containing the following 
     156     * name: name of the setting 
     157     * defaultvalue: default value for setting 
     158     * type: (string, int, real, bool) type for value of setting 
     159     * required: (0,1) whether the setting is required or not 
     160     * description: brief description for what this setting is used for. 
     161     */ 
     162    function addingRecordDefaultSettings(){ 
     163 
     164        $settings = parent::addingRecordDefaultSettings(); 
     165 
     166        for($i=0; $i< count($settings); $i++){ 
     167 
     168            switch($settings[$i]["name"]){ 
     169 
     170                case "reportTitle": 
     171                    $settings[$i]["defaultValue"] = "Work Order"; 
     172 
     173            }//endswitch 
     174 
     175        }//end foreach 
     176 
     177        return $settings; 
     178 
     179    }//endfunction addingRecordDefaultSettings 
     180 
     181}//end class 
     182 
     183 
     184/** 
     185 * PROCESSING 
     186 * ============================================================================= 
     187 */ 
    140188if(!isset($noOutput)){ 
    141189 
    142         $report = new workorderPDF($db, 'P', 'in', 'Letter'); 
    143  
    144         $report->setupFromPrintScreen(); 
    145         $report->generate(); 
    146         $filename = 'Work_Order'; 
    147         if($report->count === 1){ 
    148                  
    149                 if($report->invoicerecord["company"]) 
    150                         $filename .= "_".$report->invoicerecord["company"]; 
    151                  
    152                 $filename .= "_".$report->invoicerecord["id"]; 
    153                  
    154         }elseif((int)$report->count) 
    155                 $filename .= "_Multiple"; 
    156          
    157         $filename .= ".pdf"; 
    158         $report->output('screen', $filename); 
     190    //IE needs caching to be set to private in order to display PDFS 
     191    session_cache_limiter('private'); 
     192 
     193    //set encoding to latin1 (fpdf doesnt like utf8) 
     194    $sqlEncoding = "latin1"; 
     195    require_once("../../../include/session.php"); 
     196 
     197    checkForReportArguments(); 
     198 
     199    $report = new workorderPDF($db, $_GET["rid"], $_GET["tid"], 'P', 'in', 'Letter'); 
     200 
     201    $report->setupFromPrintScreen(); 
     202    $report->generate(); 
     203 
     204    $filename = 'Work_Order'; 
     205 
     206    if($report->count === 1){ 
     207 
     208        if($report->invoicerecord["company"]) 
     209            $filename .= "_".$report->invoicerecord["company"]; 
     210 
     211        $filename .= "_".$report->invoicerecord["id"]; 
     212 
     213    }elseif((int)$report->count) 
     214        $filename .= "_Multiple"; 
     215 
     216    $filename .= ".pdf"; 
     217 
     218    $report->output('screen', $filename); 
    159219 
    160220}//end if 
    161221 
     222/** 
     223 * When adding a new report record, the add/edit needs to know what the class 
     224 * name is so that it can instantiate it, and grab it's default settings. 
     225 */ 
     226if(isset($addingReportRecord)) 
     227    $reportClass ="workorderPDF"; 
    162228?> 
  • trunk/phpbms/modules/bms/report/invoices_pdf_class.php

    r673 r693  
    3838*/ 
    3939 
    40         if(!class_exists("phpbmsReport")) 
    41                 include("report/report_class.php"); 
    42  
    43         class invoicePDF extends phpbmsReport{ 
    44  
    45                 var $title = "Invoice"; 
    46                 var $showShipNameInShipTo = true; 
    47                 var $lineitemBoxHeight = 4.25; 
    48                  
    49                 /** 
    50                   * $count 
    51                   * @var int The number of invoice records being displayed 
    52                   */ 
    53                 var $count; 
    54  
    55                 function invoicePDF($db, $orientation='P', $unit='mm', $format='Letter'){ 
    56  
    57                         $this->db = $db; 
    58  
    59                         if(!class_exists("phpbmsPDFReport")) 
    60                                 include("report/pdfreport_class.php"); 
    61  
    62                         $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); 
    63  
    64                         $this->initialize(); 
    65  
    66                 }//end method 
    67  
    68  
    69                 function initialize(){ 
    70                         //This function will set column headings, sizes and formatting 
    71  
    72                         $pdf = &$this->pdf; 
    73  
    74                         $topinfo = array(); 
    75                         $topinfo[] = new pdfColumn("Order ID", "id", 0.75); 
    76                         $topinfo[] = new pdfColumn("Order Date", "orderdate", 1, "date"); 
    77                         $topinfo[] = new pdfColumn("Client PO", "ponumber", 1); 
    78                         $topinfo[] = new pdfColumn("Processed By", "processedby", 0); 
    79                         $topinfo[] = new pdfColumn("Payment Method", "paymentname",2); 
    80  
    81                         $size = 0; 
    82                         foreach($topinfo as $column) 
    83                                 $size += $column->size; 
    84  
    85                         $topinfo[3]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    86  
    87                         $this->topinfo = $topinfo; 
    88  
    89  
    90                         $lineitems = array(); 
    91                         $lineitems[] = new pdfColumn("Product / (Part Number)", "parts", 0); 
    92                         $lineitems[] = new pdfColumn("Tax", "taxable", 0.5, "boolean", "C"); 
    93                         $lineitems[] = new pdfColumn("Unit Price", "unitprice", 0.75, "currency", "R"); 
    94                         $lineitems[] = new pdfColumn("Qty", "quantity", 0.5, "real","R"); 
    95                         $lineitems[] = new pdfColumn("Extended", "extended", 0.75, "currency", "R"); 
    96  
    97                         $size = 0; 
    98                         foreach($lineitems as $column) 
    99                                 $size += $column->size; 
    100  
    101                         $lineitems[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    102  
    103                         $this->lineitems = $lineitems; 
    104  
    105                         $totalsinfo = array(); 
    106                         $totalsinfo[] = new pdfColumn("Discount", "discountamount", 1, "currency", "R"); 
    107                         $totalsinfo[] = new pdfColumn("Subtotal", "totaltni", 0, "currency", "R"); 
    108                         $totalsinfo[] = new pdfColumn("Tax", "tax", 1, "currency", "R"); 
    109                         $totalsinfo[] = new pdfColumn("Shipping", "shipping", 1, "currency", "R"); 
    110                         $totalsinfo[] = new pdfColumn("Total", "totalti", 1, "currency", "R"); 
    111                         $totalsinfo[] = new pdfColumn("Due", "amountdue", 1, "currency", "R"); 
    112  
    113                         $this->totalsinfo = $totalsinfo; 
    114  
    115                 }//end method 
    116  
    117  
    118                 function generate($whereclause = NULL, $sortorder = "invoices.id"){ 
    119  
    120                         $pdf = &$this->pdf; 
    121  
    122                         if($whereclause) 
    123                                 $this->whereclause = $whereclause; 
    124                         elseif(!$this->whereclause) 
    125                                 $this->whereclause = "invoices.id = -400"; 
    126  
    127                         if($sortorder) 
    128                                 $this->sortorder = $sortorder; 
    129                         elseif(!$this->sortorder) 
    130                                 $this->sortorder = "invoices.id"; 
    131  
    132                         $paymentFields = ""; 
    133                         if(ENCRYPT_PAYMENT_FIELDS){ 
    134  
    135                                 $paymentFields = " 
    136                                         ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, 
    137                                         ".$this->db->decrypt("`ccverification`")." AS `ccverification`, 
    138                                         ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, 
    139                                         ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, 
    140                                         ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, 
    141                                 "; 
    142  
    143                         }//end if 
    144  
    145                         $querystatement = " 
    146                                 SELECT 
    147                                         invoices.*, 
    148                                         ".$paymentFields." 
    149  
    150                                         invoices.totalti - invoices.amountpaid AS amountdue, 
    151  
    152                                         clients.firstname, 
    153                                         clients.lastname, 
    154                                         clients.company, 
    155                                         clients.homephone, 
    156                                         clients.workphone, 
    157                                         clients.email, 
    158  
    159                                         shippingmethods.name AS shippingname, 
    160  
    161                                         paymentmethods.name AS paymentname, 
    162                                         paymentmethods.type AS paymenttype, 
    163  
    164                                         tax.name as taxname, 
    165  
    166                                         users.firstname AS processorfirst, 
    167                                         users.lastname AS processorlast 
    168  
    169                                 FROM 
    170                                         invoices INNER JOIN clients ON invoices.clientid = clients.uuid 
    171                                         INNER JOIN users ON invoices.modifiedby = users.id 
    172                                         LEFT JOIN shippingmethods ON invoices.shippingmethodid = shippingmethods.uuid 
    173                                         LEFT JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid 
    174                                         LEFT JOIN tax ON invoices.taxareaid = tax.uuid"; 
    175  
    176                         $querystatement = $this->assembleSQL($querystatement); 
    177                         $queryresult = $this->db->query($querystatement); 
    178  
    179                         $this->count = $this->db->numRows($queryresult); 
    180                         if($this->count == 0){ 
    181                                  
    182                                 $this->_showNoRecords(); 
    183                                 exit; 
    184  
    185                         }//end if 
    186  
    187  
    188                         $pdf->hasComapnyHeader = true; 
    189                         $pdf->SetMargins(); 
    190  
    191                         //iterate through each invoice record 
    192                         while($invoicerecord = $this->db->fetchArray($queryresult)){ 
    193  
    194                                 $this->page = 0; 
    195  
    196                                 $this->invoicerecord = $invoicerecord; 
    197  
    198                                 //adds top info 
    199                                 $top = $this->_addPage(); 
    200  
    201                                 $this->_addLineItems($top); 
    202  
    203                                 $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); 
    204  
    205                                 //Print any special/instructions and stuff 
    206                                 $this->_addNotes(); 
    207  
    208                                 //totals 
    209                                 $this->_addTotals(); 
    210  
    211                                 //payment details 
    212                                 $this->_addPaymentDetails(); 
    213  
    214                         }//end while; 
    215  
    216  
    217                 }//end method 
    218  
    219  
    220                 function _addPage(){ 
    221  
    222                         $pdf = &$this->pdf; 
    223  
    224  
    225                         $pdf->AddPage(); 
    226                         $this->page++; 
    227  
    228                         $nextY = $pdf->getY(); 
    229  
    230                         //TITLE 
    231                         $title = "Statement"; 
    232                         $titleWidth=2.375; 
    233                         $titleHeight=.25; 
    234                         $pdf->setStyle("title"); 
    235                         $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); 
    236                         $pdf->Cell($titleWidth, $titleHeight,$this->title, $pdf->borderDebug,1,"R"); 
    237  
    238                         $startY = $pdf->GetY() + 0.75; 
    239  
    240                         //page number? 
    241                         $pdf->setStyle("normal"); 
    242                         $pageNoWidth = 1; 
    243                         $pdf->SetFontSize(8); 
    244                         $pdf->SetXY(-1*($pageNoWidth + $pdf->rightmargin), $pdf->topmargin + $titleHeight + 0.25); 
    245                         $pdf->Cell($pageNoWidth, 0.17, "page: ".$this->page, $pdf->borderDebug,1,"R"); 
    246  
    247  
    248                         //SOLD TO 
    249                         $boxHeight = 1.75; 
    250                         $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; 
    251  
    252                         $pdf->setLineWidth(0.02); 
    253                         $pdf->Rect($pdf->leftmargin, $startY, $boxWidth, $boxHeight); 
    254                         $pdf->setLineWidth(0.01); 
    255  
    256                         $pdf->setStyle("header"); 
    257                         $pdf->setY($startY); 
    258                         $pdf->Cell($boxWidth, 0.17, "SOLD TO", $pdf->borderDebug, 2, "L", 1); 
    259                         $pdf->setStyle("normal"); 
    260  
    261                         //Company Name 
    262                         $companyDisplay = ""; 
    263                         if($this->invoicerecord["company"]){ 
    264                                 $companyDisplay .= $this->invoicerecord["company"]; 
    265                                 if($this->invoicerecord["firstname"]) 
    266                                         $companyDisplay .= " (".$this->invoicerecord["firstname"]." ".$this->invoicerecord["lastname"].")"; 
    267                         } else 
    268                                 $companyDisplay .= $this->invoicerecord["firstname"]." ".$this->invoicerecord["lastname"]; 
    269  
    270                         $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
    271                         $pdf->SetFont("Arial", "B", 10); 
    272                         $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); 
    273  
    274                         $billto = $this->_setBillTo(); 
    275                         $pdf->SetFont("Arial", "", 10); 
    276                         $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
    277                         $pdf->MultiCell($boxWidth - 0.125,.17,$billto, $pdf->borderDebug); 
    278  
    279                         //SHIP TO 
    280                         $pdf->setLineWidth(0.02); 
    281                         $pdf->Rect($pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); 
    282                         $pdf->setLineWidth(0.01); 
    283  
    284                         $pdf->setStyle("header"); 
    285                         $pdf->setXY($pdf->leftmargin + $boxWidth + 0.125, $startY); 
    286                         $pdf->Cell($boxWidth, 0.17, "SHIP TO", $pdf->borderDebug, 2, "L", 1); 
    287                         $pdf->setStyle("normal"); 
    288  
    289                         $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
    290                         $pdf->SetFont("Arial", "B", 10); 
    291  
    292                         $shipDisplay = (!$this->invoicerecord["shiptosameasbilling"] && $this->invoicerecord["shiptoname"])? $this->invoicerecord["shiptoname"] :$companyDisplay; 
    293                         $pdf->Cell($boxWidth - 0.125, 0.17, $shipDisplay, $pdf->borderDebug, 2, "L"); 
    294  
    295                         $shipto = $this->_setShipTo(); 
    296                         $pdf->SetFont("Arial", "", 10); 
    297                         $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
    298                         $pdf->MultiCell($boxWidth - 0.125,.17, $shipto, $pdf->borderDebug); 
    299  
    300                         $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); 
    301  
    302                         $this->_topInvoiceInfo(); 
    303  
    304                         //line item headings 
    305                         $pdf->setStyle("header"); 
    306                         $pdf->SetLineWidth(0.02); 
    307  
    308                         $coords["x"] = $pdf->GetX(); 
    309                         $coords["y"] = $pdf->GetY(); 
    310  
    311                         foreach($this->lineitems as $column) 
    312                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    313  
    314                         return $coords; 
    315  
    316                 }//end method 
    317  
    318  
    319                 function _setBillTo(){ 
    320  
    321                         $billto = $this->invoicerecord["address1"]; 
    322  
    323                         if($this->invoicerecord["address2"]) 
    324                                 $billto .= "\n".$this->invoicerecord["address2"]; 
    325  
    326                         $billto .="\n".$this->invoicerecord["city"].", ".$this->invoicerecord["state"]." ".$this->invoicerecord["postalcode"]; 
    327  
    328                         if($this->invoicerecord["country"]) 
    329                                 $billto .=" ".$this->invoicerecord["country"]; 
    330  
    331                         $phoneemail = ""; 
    332                         if($this->invoicerecord["workphone"] || $this->invoicerecord["homephone"]){ 
    333  
    334                                 if($this->invoicerecord["workphone"]) 
    335                                         $phoneemail = $this->invoicerecord["workphone"]." (W)"; 
    336                                 else 
    337                                         $phoneemail = $this->invoicerecord["homephone"]." (H)"; 
    338  
    339                                 $phoneemail.="\n"; 
    340  
    341                         }//end if 
    342  
    343                         if($this->invoicerecord["email"]) 
    344                                 $phoneemail .= $this->invoicerecord["email"]; 
    345  
    346                         if($phoneemail) 
    347                                 $billto .= "\n\n".$phoneemail; 
    348  
    349                         return $billto; 
    350  
    351                 }//end method 
    352  
    353  
    354                 function _setShipTo(){ 
    355  
    356                         $added = ($this->invoicerecord["shiptosameasbilling"])? "" : "shipto"; 
    357  
    358                         $shipto = ""; 
    359  
    360                         $shipto .= $this->invoicerecord[$added."address1"]; 
    361  
    362                         if($this->invoicerecord[$added."address2"]) 
    363                                 $shipto .= "\n".$this->invoicerecord[$added."address2"]; 
    364  
    365                         $shipto .="\n".$this->invoicerecord[$added."city"].", ".$this->invoicerecord[$added."state"]." ".$this->invoicerecord[$added."postalcode"]; 
    366  
    367                         if($this->invoicerecord[$added."country"]) 
    368                                 $shipto .=" ".$this->invoicerecord[$added."country"]; 
    369  
    370                         if($this->showShipNameInShipTo) 
    371                                 if($this->invoicerecord["shippingname"]) 
    372                                         $shipto .="\n\nShipping Method:\n".$this->invoicerecord["shippingname"]; 
    373  
    374                         return $shipto; 
    375  
    376                 }//end method 
    377  
    378  
    379                 function _topInvoiceInfo(){ 
    380  
    381                         $pdf = &$this->pdf; 
    382  
    383                         $pdf->setStyle("header"); 
    384                         $pdf->SetLineWidth(0.02); 
    385  
    386                         foreach($this->topinfo as $column) 
    387                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    388  
    389                         $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); 
    390  
    391                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); 
    392  
    393  
    394                         $this->invoicerecord["processedby"] = $this->invoicerecord["processorfirst"]." ".$this->invoicerecord["processorlast"]; 
    395                         $pdf->setStyle("normal"); 
    396  
    397                         foreach($this->topinfo as $column){ 
    398  
    399                                 if($column->format != "") 
    400                                         $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
    401                                 else 
    402                                         $value = $this->invoicerecord[$column->fieldname]; 
    403  
    404                                 $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    405  
    406                         }//end foreach 
    407  
    408                         $pdf->SetY($pdf->GetY() + 0.18 + 0.125); 
    409  
    410                 }//end method 
    411  
    412  
    413                 function _addLineItems($coords){ 
    414  
    415                         $pdf = &$this->pdf; 
    416  
    417                         $lineitemresult = $this->_getLineItems(); 
    418  
    419                         $pdf->setStyle("normal"); 
    420  
    421                         $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
    422  
    423                         while($line = $this->db->fetchArray($lineitemresult)){ 
    424  
    425  
    426                         if($line["partname"] || $line["partnumber"] || $line["extended"]){ 
    427  
    428                                 if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ 
    429  
    430                                         $pdf->SetLineWidth(0.02); 
    431                                         $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
    432                                         $pdf->SetLineWidth(0.01); 
    433  
    434                                         $this->_addPage(); 
    435  
    436                                         $pdf->setStyle("normal"); 
    437  
    438                                         $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
    439  
    440                                 }//end if 
    441  
    442                                 foreach($this->lineitems as $column){ 
    443  
    444                                         $ln = 0; 
    445  
    446  
    447                                         switch($column->fieldname){ 
    448  
    449                                                 case "parts": 
    450                                                         $pdf->SetFont("Arial", "B", 8); 
    451                                                         $pdf->Write(0.17, $line["partname"]); 
    452                                                         $pdf->setStyle("normal"); 
    453                                                         $pdf->SetX($pdf->leftmargin + $column->size); 
    454                                                         break; 
    455  
    456                                                 default: 
    457                                                         if($column->format != "") 
    458                                                                 $value = formatVariable($line[$column->fieldname], $column->format); 
    459                                                         else 
    460                                                                 $value = $line[$column->fieldname]; 
    461  
    462                                                         if($value == "&middot;") 
    463                                                                 $value = " "; 
    464                                                         if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) 
    465                                                                 $ln = 2; 
    466  
    467                                                         $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); 
    468                                                         break; 
    469  
    470                                         }//end switch 
    471  
    472                                 }//end foreach 
    473  
    474                                 $pdf->SetX($pdf->leftmargin); 
    475                                 $pdf->Write(0.17, "(".$line["partnumber"].")"); 
    476                                 $pdf->Ln(); 
    477  
    478                                 }//endif 
    479  
    480                                 if($line["memo"]){ 
    481  
    482                                         $pdf->SetX($pdf->leftmargin + 0.0625); 
    483                                         $pdf->SetFont("Arial", "I", 8); 
    484                                         $pdf->MultiCell($this->lineitems[0]->size - 0.0625, 0.16, $line["memo"], $pdf->borderDebug); 
    485                                         $pdf->setStyle("normal"); 
    486  
    487                                 }//end if 
    488  
    489                                 $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
    490                                 $pdf->SetLineWidth(0.01); 
    491                                 $pdf->SetDrawColor(180,180,180); 
    492                                 $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); 
    493                                 $pdf->SetDrawColor(0,0,0); 
    494                                 $pdf->SetLineWidth(0.02); 
    495                                 $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
    496  
    497                         }//end while 
    498  
    499                         $pdf->SetLineWidth(0.02); 
    500                         $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
    501  
    502                 }//end method 
    503  
    504  
    505                 function _getLineItems(){ 
    506  
    507                         $querystatement = " 
    508                         SELECT 
    509                                 lineitems.*, 
    510                                 lineitems.quantity * lineitems.unitprice AS extended, 
    511                                 products.partname, 
    512                                 products.partnumber 
    513                         FROM 
    514                                 lineitems LEFT JOIN products ON lineitems.productid = products.uuid 
    515                         WHERE 
    516                                 lineitems.invoiceid ='".((int) $this->invoicerecord["id"])."' 
    517                         ORDER BY 
    518                                 displayorder"; 
    519  
    520                         $queryresult = $this->db->query($querystatement); 
    521  
    522                         return $queryresult; 
    523  
    524                 }//end method 
    525  
    526  
    527                 function _addNotes(){ 
    528  
    529                         $pdf = &$this->pdf; 
    530  
    531                         $height = 1; 
    532                         $nextPos = $pdf->GetY() + $height + 0.125; 
    533  
    534                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    535                         $pdf->setStyle("header"); 
    536                         $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes/Instructions", 1, 2, "L", 1); 
    537  
    538                         $pdf->setStyle("normal"); 
    539                         $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
    540                         $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["printedinstructions"]); 
    541  
    542                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    543  
    544                 }//end method 
    545  
    546  
    547                 function _addTotals(){ 
    548  
    549                         $pdf = &$this->pdf; 
    550  
    551                         $size = 0; 
    552                         foreach($this->totalsinfo as $column) 
    553                                 switch($column->fieldname){ 
    554                                         case "shipping": 
    555                                         case "discountamount": 
    556                                                 if($this->invoicerecord[$column->fieldname]) 
    557                                                         $size += $column->size; 
    558                                                 break; 
    559                                         default: 
    560                                                 $size += $column->size; 
    561                                 }//endswitch 
    562                         $this->totalsinfo[1]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    563  
    564                         $height = .5; 
    565                         $nextPos = $pdf->GetY() + $height + 0.125; 
    566  
    567                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    568  
    569                         $pdf->setStyle("header"); 
    570                         foreach($this->totalsinfo as $column) 
    571                                 switch($column->fieldname){ 
    572                                         case "shipping": 
    573                                         case "discountamount": 
    574                                                 if($this->invoicerecord[$column->fieldname]) 
    575                                                         $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    576                                                 break; 
    577                                         default: 
    578                                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    579                                 }//endswitch 
    580  
    581                         $pdf->setStyle("normal"); 
    582                         $pdf->SetFont("Arial", "B", 10); 
    583                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
    584  
    585                         foreach($this->totalsinfo as $column){ 
    586  
    587                                 if($column->format != "") 
    588                                         $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
    589                                 else 
    590                                         $value = $this->invoicerecord[$column->fieldname]; 
    591  
    592                                 switch($column->fieldname){ 
    593                                         case "shipping": 
    594                                         case "discountamount": 
    595                                                 if($this->invoicerecord[$column->fieldname]) 
    596                                                         $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    597                                                 break; 
    598                                         default: 
    599                                                 $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    600                                 }//endswitch 
    601                         }//end foreach 
    602                         $this->totalsinfo[1]->size = 0; 
    603  
    604                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    605  
    606                 }//end method 
    607  
    608  
    609                 function _addPaymentDetails(){ 
    610                 }//end method 
    611  
    612  
    613                 function output($destination = "screen" , $userinfo = NULL){ 
    614  
    615                         switch($destination){ 
    616  
    617                                 case "screen": 
    618                                         $userinfo = cleanFilename((string)$userinfo); 
    619                                         $this->pdf->Output($userinfo, 'D'); 
    620                                         break; 
    621  
    622                                 case "email": 
    623  
    624                                         if(!$userinfo) 
    625                                                 $userinfo = $_SESSION["userinfo"]; 
    626  
    627                                         if(!$userinfo["email"] || !$this->invoicerecord["email"]) 
    628                                                 return false; 
    629  
    630                                         $pdf = $this->pdf->Output(NULL, "S"); 
    631  
    632                                         $to =           $this->invoicerecord["email"]; 
    633                                         $from =         $userinfo["email"]; 
    634                                         $subject =      "Your ".$this->title." from ".COMPANY_NAME; 
    635                                         $message =      "Attached is your ".$this->title." from ".COMPANY_NAME."\n\n" . 
    636                                                                 "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . 
    637                                                                 "have Acrobat Reader, you can download it at http://www.adobe.com  \n\n" . 
    638                                                                 COMPANY_NAME."\n". 
    639                                                                 COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; 
    640  
    641                                         $headers = "From: $from"; 
    642  
    643                                         $semi_rand = md5( time() ); 
    644                                         $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    645  
    646                                         $headers .= "\nMIME-Version: 1.0\n" . 
    647                                                                 "Content-Type: multipart/mixed;\n" . 
    648                                                                 " boundary=\"{$mime_boundary}\""; 
    649  
    650                                         $message = "This is a multi-part message in MIME format.\n\n" . 
    651                                                         "--{$mime_boundary}\n" . 
    652                                                         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
    653                                                         "Content-Transfer-Encoding: 7bit\n\n" . 
    654                                                         $message . "\n\n"; 
    655  
    656                                         $pdf = chunk_split( base64_encode( $pdf ) ); 
    657  
    658                                         $message .= "--{$mime_boundary}\n" . 
    659                                                          "Content-Type: {application/pdf};\n" . 
    660                                                          " name=\"".$this->title.$this->invoicerecord["id"].".pdf\"\n" . 
    661                                                          "Content-Disposition: attachment;\n" . 
    662                                                          " filename=\"".$this->title.$this->invoicerecord["id"].".pdf\"\n" . 
    663                                                          "Content-Transfer-Encoding: base64\n\n" . 
    664                                                          $pdf . "\n\n" . 
    665                                                          "--{$mime_boundary}--\n"; 
    666  
    667                                         return @ mail($to, $subject, $message, $headers); 
    668  
    669                                         break; 
    670  
    671                         }//endswitch 
    672  
    673                 }//end method 
    674  
    675         }//end class 
     40if(!class_exists("phpbmsReport")) 
     41    include("../../../report/report_class.php"); 
     42 
     43class invoicePDF extends phpbmsReport{ 
     44 
     45    var $showShipNameInShipTo = true; 
     46    var $lineitemBoxHeight = 4.25; 
     47    var $templateUUID = NULL; 
     48 
     49    /** 
     50      * $count 
     51      * @var int The number of invoice records being displayed 
     52      */ 
     53    var $count; 
     54 
     55 
     56    function invoicePDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ 
     57 
     58        parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     59 
     60        if(!class_exists("phpbmsPDFReport")) 
     61            include("report/pdfreport_class.php"); 
     62 
     63        $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); 
     64 
     65        $this->checkForDefaultSettings(); 
     66        $this->initialize(); 
     67 
     68    }//end method 
     69 
     70 
     71    /** 
     72     * function checkForDefaultSettings 
     73     * 
     74     * Checks to make sure loaded report Settings exist and are correct 
     75     */ 
     76    function checkForDefaultSettings(){ 
     77 
     78        if(!isset($this->settings["reportTitle"])) 
     79            $this->settings["reportTitle"] = "Invoice"; 
     80 
     81        if(!isset($this->settings["printLogo"])) 
     82            $this->settings["printLogo"] = 1; 
     83 
     84        if(!isset($this->settings["printCompanyInfo"])) 
     85            $this->settings["printCompanyInfo"] = 1; 
     86 
     87        if(!isset($this->settings["leftTopBox"])) 
     88            $this->settings["leftTopBox"] = "billto"; 
     89 
     90        if(!isset($this->settings["leftTopBoxTitle"])) 
     91            $this->settings["leftTopBoxTitle"] = "SOLD TO"; 
     92 
     93        if(!isset($this->settings["rightTopBox"])) 
     94            $this->settings["rightTopBox"] = "shipto"; 
     95 
     96        if(!isset($this->settings["rightTopBoxTitle"])) 
     97            $this->settings["rightTopBoxTitle"] = "SHIP TO"; 
     98 
     99        if(!isset($this->settings["templateFormatting"])) 
     100            $this->settings["templateFormatting"] = 0; 
     101 
     102        if(!isset($this->settings["templateUUID"])) 
     103            $this->settings["templateUUID"] = ""; 
     104 
     105    }//end function checkForDefaultSettings 
     106 
     107 
     108    function initialize(){ 
     109            //This function will set column headings, sizes and formatting 
     110 
     111            $pdf = &$this->pdf; 
     112 
     113            $topinfo = array(); 
     114            $topinfo[] = new pdfColumn("Order ID", "id", 0.75); 
     115            $topinfo[] = new pdfColumn("Order Date", "orderdate", 1, "date"); 
     116            $topinfo[] = new pdfColumn("Client PO", "ponumber", 1); 
     117            $topinfo[] = new pdfColumn("Processed By", "processedby", 0); 
     118            $topinfo[] = new pdfColumn("Payment Method", "paymentname",2); 
     119 
     120            $size = 0; 
     121            foreach($topinfo as $column) 
     122                    $size += $column->size; 
     123 
     124            $topinfo[3]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     125 
     126            $this->topinfo = $topinfo; 
     127 
     128 
     129            $lineitems = array(); 
     130            $lineitems[] = new pdfColumn("Product / (Part Number)", "parts", 0); 
     131            $lineitems[] = new pdfColumn("Tax", "taxable", 0.5, "boolean", "C"); 
     132            $lineitems[] = new pdfColumn("Unit Price", "unitprice", 0.75, "currency", "R"); 
     133            $lineitems[] = new pdfColumn("Qty", "quantity", 0.5, "real","R"); 
     134            $lineitems[] = new pdfColumn("Extended", "extended", 0.75, "currency", "R"); 
     135 
     136            $size = 0; 
     137            foreach($lineitems as $column) 
     138                    $size += $column->size; 
     139 
     140            $lineitems[0]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     141 
     142            $this->lineitems = $lineitems; 
     143 
     144            $totalsinfo = array(); 
     145            $totalsinfo[] = new pdfColumn("Discount", "discountamount", 1, "currency", "R"); 
     146            $totalsinfo[] = new pdfColumn("Subtotal", "totaltni", 0, "currency", "R"); 
     147            $totalsinfo[] = new pdfColumn("Tax", "tax", 1, "currency", "R"); 
     148            $totalsinfo[] = new pdfColumn("Shipping", "shipping", 1, "currency", "R"); 
     149            $totalsinfo[] = new pdfColumn("Total", "totalti", 1, "currency", "R"); 
     150            $totalsinfo[] = new pdfColumn("Due", "amountdue", 1, "currency", "R"); 
     151 
     152            $this->totalsinfo = $totalsinfo; 
     153 
     154    }//end method 
     155 
     156 
     157    function generate($whereclause = NULL, $sortorder = "invoices.id"){ 
     158 
     159            $pdf = &$this->pdf; 
     160 
     161            if($whereclause) 
     162                    $this->whereClause = $whereclause; 
     163            elseif(!$this->whereClause) 
     164                    $this->whereClause = "invoices.id = -400"; 
     165 
     166            if($sortorder) 
     167                    $this->sortOrder = $sortorder; 
     168            elseif(!$this->sortOrder) 
     169                    $this->sortOrder = "invoices.id"; 
     170 
     171            $paymentFields = ""; 
     172            if(ENCRYPT_PAYMENT_FIELDS){ 
     173 
     174                    $paymentFields = " 
     175                            ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, 
     176                            ".$this->db->decrypt("`ccverification`")." AS `ccverification`, 
     177                            ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, 
     178                            ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, 
     179                            ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, 
     180                    "; 
     181 
     182            }//end if 
     183 
     184            $querystatement = " 
     185                    SELECT 
     186                            invoices.*, 
     187                            ".$paymentFields." 
     188 
     189                            invoices.totalti - invoices.amountpaid AS amountdue, 
     190 
     191                            clients.firstname, 
     192                            clients.lastname, 
     193                            clients.company, 
     194                            clients.homephone, 
     195                            clients.workphone, 
     196                            clients.email, 
     197 
     198                            shippingmethods.name AS shippingname, 
     199 
     200                            paymentmethods.name AS paymentname, 
     201                            paymentmethods.type AS paymenttype, 
     202 
     203                            tax.name as taxname, 
     204 
     205                            users.firstname AS processorfirst, 
     206                            users.lastname AS processorlast 
     207 
     208                    FROM 
     209                            invoices INNER JOIN clients ON invoices.clientid = clients.uuid 
     210                            INNER JOIN users ON invoices.modifiedby = users.id 
     211                            LEFT JOIN shippingmethods ON invoices.shippingmethodid = shippingmethods.uuid 
     212                            LEFT JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid 
     213                            LEFT JOIN tax ON invoices.taxareaid = tax.uuid"; 
     214 
     215            $querystatement = $this->assembleSQL($querystatement); 
     216 
     217            $queryresult = $this->db->query($querystatement); 
     218 
     219            $this->count = $this->db->numRows($queryresult); 
     220            if($this->count == 0){ 
     221 
     222                    $this->showNoRecords(); 
     223                    exit; 
     224 
     225            }//end if 
     226 
     227            $pdf->logoInHeader = $this->settings["printLogo"]; 
     228            $pdf->companyInfoInHeader = $this->settings["printCompanyInfo"]; 
     229 
     230            $pdf->SetMargins(); 
     231 
     232            //iterate through each invoice record 
     233            while($invoicerecord = $this->db->fetchArray($queryresult)){ 
     234 
     235                    $this->page = 0; 
     236 
     237                    $this->invoicerecord = $invoicerecord; 
     238 
     239                    //adds top info 
     240                    $top = $this->_addPage(); 
     241 
     242                    $this->_addLineItems($top); 
     243 
     244                    $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); 
     245 
     246                    //Print any special/instructions and stuff 
     247                    $this->_addNotes(); 
     248 
     249                    //totals 
     250                    $this->_addTotals(); 
     251 
     252                    //payment details 
     253                    $this->_addPaymentDetails(); 
     254 
     255            }//end while; 
     256 
     257 
     258    }//end method 
     259 
     260 
     261    function _addPage(){ 
     262 
     263            $pdf = &$this->pdf; 
     264 
     265            $pdf->AddPage(); 
     266 
     267            if($this->settings["templateUUID"]){ 
     268 
     269                if(!isset($GLOBALS["pdfDoc"])){ 
     270 
     271                    $querystatement = " 
     272                        SELECT 
     273                            `file` 
     274                        FROM 
     275                            `files` 
     276                        WHERE 
     277                            `uuid` = '".$this->settings["templateUUID"]."'"; 
     278 
     279                    $queryresult = $this->db->query($querystatement); 
     280 
     281                    $therecord = $this->db->fetchArray($queryresult); 
     282 
     283                    $GLOBALS["pdfDoc"] = $therecord["file"]; 
     284                    $pdf->setSourceFile("global://pdfDoc"); 
     285                    $this->tplIdx = $pdf->importPage(1); 
     286 
     287                }//endif 
     288 
     289                $pdf->useTemplate($this->tplIdx); 
     290 
     291            }//endif 
     292 
     293 
     294            $this->page++; 
     295 
     296            $nextY = $pdf->getY(); 
     297 
     298            //TITLE 
     299            $title = "Statement"; 
     300            $titleWidth=2.375; 
     301            $titleHeight=.25; 
     302            $pdf->setStyle("title"); 
     303            $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); 
     304            $pdf->Cell($titleWidth, $titleHeight, $this->settings["reportTitle"], $pdf->borderDebug,1,"R"); 
     305 
     306            $startY = $pdf->GetY() + 0.75; 
     307 
     308            //page number? 
     309            $pdf->setStyle("normal"); 
     310            $pageNoWidth = 1; 
     311            $pdf->SetFontSize(8); 
     312            $pdf->SetXY(-1*($pageNoWidth + $pdf->rightmargin), $pdf->topmargin + $titleHeight + 0.25); 
     313            $pdf->Cell($pageNoWidth, 0.17, "page: ".$this->page, $pdf->borderDebug,1,"R"); 
     314 
     315            $boxHeight = 1.75; 
     316            $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; 
     317 
     318            //Left Top Box 
     319            $this->_addTopBox($this->settings["leftTopBox"], $this->settings["leftTopBoxTitle"], $pdf->leftmargin, $startY, $boxWidth, $boxHeight); 
     320 
     321            //Right Top Box 
     322            $this->_addTopBox($this->settings["rightTopBox"], $this->settings["rightTopBoxTitle"], $pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); 
     323 
     324            $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); 
     325 
     326            $this->_topInvoiceInfo(); 
     327 
     328 
     329            $coords["x"] = $pdf->GetX(); 
     330            $coords["y"] = $pdf->GetY(); 
     331 
     332            if(!$this->settings["templateFormatting"]){ 
     333 
     334                //line item headings 
     335                $pdf->setStyle("header"); 
     336                $pdf->SetLineWidth(0.02); 
     337 
     338                foreach($this->lineitems as $column) 
     339                    $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     340 
     341            }//endif 
     342 
     343            return $coords; 
     344 
     345    }//end method 
     346 
     347 
     348    function _addTopBox($areaToPrint, $title, $x, $y, $boxWidth, $boxHeight){ 
     349 
     350        if($areaToPrint != "noshow"){ 
     351 
     352            $pdf = &$this->pdf; 
     353 
     354            if(!$this->settings["templateFormatting"]){ 
     355 
     356                $pdf->setLineWidth(0.02); 
     357                $pdf->Rect($x, $y, $boxWidth, $boxHeight); 
     358                $pdf->setLineWidth(0.01); 
     359 
     360                $pdf->setStyle("header"); 
     361                $pdf->setXY($x, $y); 
     362                $pdf->Cell($boxWidth, 0.17, $title, $pdf->borderDebug, 2, "L", 1); 
     363                $pdf->setStyle("normal"); 
     364 
     365            } else 
     366                $pdf->SetXY($x ,$y + 0.17); 
     367 
     368            $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     369 
     370            switch($areaToPrint){ 
     371 
     372                case "billto": 
     373 
     374                    $companyDisplay = ""; 
     375                    if($this->invoicerecord["company"]){ 
     376 
     377                            $companyDisplay .= $this->invoicerecord["company"]; 
     378                            if($this->invoicerecord["firstname"]) 
     379                                    $companyDisplay .= " (".$this->invoicerecord["firstname"]." ".$this->invoicerecord["lastname"].")"; 
     380 
     381                    } else 
     382                            $companyDisplay .= $this->invoicerecord["firstname"]." ".$this->invoicerecord["lastname"]; 
     383 
     384                    $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     385                    $pdf->SetFont("Arial", "B", 10); 
     386                    $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); 
     387 
     388                    $billto = $this->_setBillTo(); 
     389                    $pdf->SetFont("Arial", "", 10); 
     390                    $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     391                    $pdf->MultiCell($boxWidth - 0.125,.17,$billto, $pdf->borderDebug); 
     392                    break; 
     393 
     394                case "shipto": 
     395 
     396                    $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     397                    $pdf->SetFont("Arial", "B", 10); 
     398 
     399                    $shipDisplay = (!$this->invoicerecord["shiptosameasbilling"] && $this->invoicerecord["shiptoname"])? $this->invoicerecord["shiptoname"] :$companyDisplay; 
     400                    $pdf->Cell($boxWidth - 0.125, 0.17, $shipDisplay, $pdf->borderDebug, 2, "L"); 
     401 
     402                    $shipto = $this->_setShipTo(); 
     403                    $pdf->SetFont("Arial", "", 10); 
     404                    $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     405                    $pdf->MultiCell($boxWidth - 0.125,.17, $shipto, $pdf->borderDebug); 
     406                    break; 
     407 
     408                case "companyinfo": 
     409 
     410                    $cname = COMPANY_NAME; 
     411                    $caddress = COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; 
     412 
     413                    $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     414                    $pdf->SetFont("Arial","B",10); 
     415                    $pdf->Cell($boxWidth - 0.125, 0.17, $cname, $pdf->borderDebug, 2, "L"); 
     416 
     417                    //and last, company address 
     418                    $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     419                    $pdf->SetFont("Arial", "", 10); 
     420                    $pdf->MultiCell($boxWidth - 0.125,.17 , $caddress, $pdf->borderDebug); 
     421                    break; 
     422 
     423                case "invoiceinfo": 
     424 
     425                    $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     426                    $pdf->SetFont("Arial","B",14); 
     427                    $pdf->Cell($boxWidth - 0.125, 0.25, $this->invoicerecord["id"], $pdf->borderDebug, 2, "R"); 
     428 
     429 
     430                    $details = "payment method\n".$this->invoicerecord["paymentname"]; 
     431                    $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.125); 
     432                    $pdf->SetFont("Arial", "", 8); 
     433                    $pdf->MultiCell($boxWidth - 0.125,.17, $details, $pdf->borderDebug, "R"); 
     434 
     435                    break; 
     436 
     437            }//endswitch 
     438 
     439        }//endif 
     440 
     441    }//end function _addTopBox 
     442 
     443 
     444    function _setBillTo(){ 
     445 
     446            $billto = $this->invoicerecord["address1"]; 
     447 
     448            if($this->invoicerecord["address2"]) 
     449                    $billto .= "\n".$this->invoicerecord["address2"]; 
     450 
     451            $billto .="\n".$this->invoicerecord["city"].", ".$this->invoicerecord["state"]." ".$this->invoicerecord["postalcode"]; 
     452 
     453            if($this->invoicerecord["country"]) 
     454                    $billto .=" ".$this->invoicerecord["country"]; 
     455 
     456            $phoneemail = ""; 
     457            if($this->invoicerecord["workphone"] || $this->invoicerecord["homephone"]){ 
     458 
     459                    if($this->invoicerecord["workphone"]) 
     460                            $phoneemail = $this->invoicerecord["workphone"]." (W)"; 
     461                    else 
     462                            $phoneemail = $this->invoicerecord["homephone"]." (H)"; 
     463 
     464                    $phoneemail.="\n"; 
     465 
     466            }//end if 
     467 
     468            if($this->invoicerecord["email"]) 
     469                    $phoneemail .= $this->invoicerecord["email"]; 
     470 
     471            if($phoneemail) 
     472                    $billto .= "\n\n".$phoneemail; 
     473 
     474            return $billto; 
     475 
     476    }//end method 
     477 
     478 
     479    function _setShipTo(){ 
     480 
     481            $added = ($this->invoicerecord["shiptosameasbilling"])? "" : "shipto"; 
     482 
     483            $shipto = ""; 
     484 
     485            $shipto .= $this->invoicerecord[$added."address1"]; 
     486 
     487            if($this->invoicerecord[$added."address2"]) 
     488                    $shipto .= "\n".$this->invoicerecord[$added."address2"]; 
     489 
     490            $shipto .="\n".$this->invoicerecord[$added."city"].", ".$this->invoicerecord[$added."state"]." ".$this->invoicerecord[$added."postalcode"]; 
     491 
     492            if($this->invoicerecord[$added."country"]) 
     493                    $shipto .=" ".$this->invoicerecord[$added."country"]; 
     494 
     495            if($this->showShipNameInShipTo) 
     496                    if($this->invoicerecord["shippingname"]) 
     497                            $shipto .="\n\nShipping Method:\n".$this->invoicerecord["shippingname"]; 
     498 
     499            return $shipto; 
     500 
     501    }//end method 
     502 
     503 
     504    function _topInvoiceInfo(){ 
     505 
     506            $pdf = &$this->pdf; 
     507 
     508            if(!$this->settings["templateFormatting"]){ 
     509 
     510                $pdf->setStyle("header"); 
     511                $pdf->SetLineWidth(0.02); 
     512 
     513                foreach($this->topinfo as $column) 
     514                        $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     515 
     516                $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); 
     517 
     518            }//endif 
     519 
     520            $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); 
     521 
     522 
     523            $this->invoicerecord["processedby"] = $this->invoicerecord["processorfirst"]." ".$this->invoicerecord["processorlast"]; 
     524            $pdf->setStyle("normal"); 
     525 
     526            foreach($this->topinfo as $column){ 
     527 
     528                    if($column->format != "") 
     529                            $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
     530                    else 
     531                            $value = $this->invoicerecord[$column->fieldname]; 
     532 
     533                    $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     534 
     535            }//end foreach 
     536 
     537            $pdf->SetY($pdf->GetY() + 0.18 + 0.125); 
     538 
     539    }//end method 
     540 
     541 
     542    function _addLineItems($coords){ 
     543 
     544            $pdf = &$this->pdf; 
     545 
     546            $lineitemresult = $this->_getLineItems(); 
     547 
     548            $pdf->setStyle("normal"); 
     549 
     550            $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
     551 
     552            while($line = $this->db->fetchArray($lineitemresult)){ 
     553 
     554 
     555                if($line["partname"] || $line["partnumber"] || $line["extended"]){ 
     556 
     557                    if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ 
     558 
     559                        if(!$this->settings["templateFormatting"]){ 
     560 
     561                            $pdf->SetLineWidth(0.02); 
     562                            $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
     563                            $pdf->SetLineWidth(0.01); 
     564 
     565                        }//endif 
     566 
     567                        $this->_addPage(); 
     568 
     569                        $pdf->setStyle("normal"); 
     570 
     571                        $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
     572 
     573                    }//end if 
     574 
     575                    foreach($this->lineitems as $column){ 
     576 
     577                            $ln = 0; 
     578 
     579 
     580                            switch($column->fieldname){ 
     581 
     582                                    case "parts": 
     583                                            $pdf->SetFont("Arial", "B", 8); 
     584                                            $pdf->Write(0.17, $line["partname"]); 
     585                                            $pdf->setStyle("normal"); 
     586                                            $pdf->SetX($pdf->leftmargin + $column->size); 
     587                                            break; 
     588 
     589                                    default: 
     590                                            if($column->format != "") 
     591                                                    $value = formatVariable($line[$column->fieldname], $column->format); 
     592                                            else 
     593                                                    $value = $line[$column->fieldname]; 
     594 
     595                                            if($value == "&middot;") 
     596                                                    $value = " "; 
     597                                            if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) 
     598                                                    $ln = 2; 
     599 
     600                                            $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); 
     601                                            break; 
     602 
     603                            }//end switch 
     604 
     605                    }//end foreach 
     606 
     607                    $pdf->SetX($pdf->leftmargin); 
     608                    $pdf->Write(0.17, "(".$line["partnumber"].")"); 
     609                    $pdf->Ln(); 
     610 
     611                }//endif 
     612 
     613                if($line["memo"]){ 
     614 
     615                    $pdf->SetX($pdf->leftmargin + 0.0625); 
     616                    $pdf->SetFont("Arial", "I", 8); 
     617                    $pdf->MultiCell($this->lineitems[0]->size - 0.0625, 0.16, $line["memo"], $pdf->borderDebug); 
     618                    $pdf->setStyle("normal"); 
     619 
     620                }//end if 
     621 
     622                if(!$this->settings["templateFormatting"]){ 
     623 
     624                    $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
     625                    $pdf->SetLineWidth(0.01); 
     626                    $pdf->SetDrawColor(180,180,180); 
     627                    $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); 
     628                    $pdf->SetDrawColor(0,0,0); 
     629                    $pdf->SetLineWidth(0.02); 
     630 
     631                }//endif 
     632 
     633                $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
     634 
     635            }//end while 
     636 
     637            if(!$this->settings["templateFormatting"]){ 
     638 
     639                $pdf->SetLineWidth(0.02); 
     640                $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
     641                $pdf->SetLineWidth(0.01); 
     642 
     643            }//endif 
     644 
     645    }//end method 
     646 
     647 
     648    function _getLineItems(){ 
     649 
     650            $querystatement = " 
     651            SELECT 
     652                    lineitems.*, 
     653                    lineitems.quantity * lineitems.unitprice AS extended, 
     654                    products.partname, 
     655                    products.partnumber 
     656            FROM 
     657                    lineitems LEFT JOIN products ON lineitems.productid = products.uuid 
     658            WHERE 
     659                    lineitems.invoiceid ='".((int) $this->invoicerecord["id"])."' 
     660            ORDER BY 
     661                    displayorder"; 
     662 
     663            $queryresult = $this->db->query($querystatement); 
     664 
     665            return $queryresult; 
     666 
     667    }//end method 
     668 
     669 
     670    function _addNotes(){ 
     671 
     672            $pdf = &$this->pdf; 
     673 
     674            $height = 1; 
     675            $nextPos = $pdf->GetY() + $height + 0.125; 
     676 
     677            if(!$this->settings["templateFormatting"]){ 
     678 
     679                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     680                $pdf->setStyle("header"); 
     681                $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes/Instructions", 1, 2, "L", 1); 
     682                $pdf->setStyle("normal"); 
     683 
     684            } else 
     685                $pdf->SetY($pdf->GetY() + 0.18); 
     686 
     687            $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
     688            $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->invoicerecord["printedinstructions"]); 
     689 
     690            $pdf->SetXY($pdf->leftmargin, $nextPos); 
     691 
     692    }//end method 
     693 
     694 
     695    function _addTotals(){ 
     696 
     697            $pdf = &$this->pdf; 
     698 
     699            $size = 0; 
     700            foreach($this->totalsinfo as $column) 
     701                    switch($column->fieldname){ 
     702                            case "shipping": 
     703                            case "discountamount": 
     704                                    if($this->invoicerecord[$column->fieldname]) 
     705                                            $size += $column->size; 
     706                                    break; 
     707                            default: 
     708                                    $size += $column->size; 
     709                    }//endswitch 
     710            $this->totalsinfo[1]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     711 
     712            $height = .5; 
     713            $nextPos = $pdf->GetY() + $height + 0.125; 
     714 
     715            if(!$this->settings["templateFormatting"]){ 
     716 
     717                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     718 
     719                $pdf->setStyle("header"); 
     720                foreach($this->totalsinfo as $column) 
     721                    switch($column->fieldname){ 
     722 
     723                        case "shipping": 
     724                        case "discountamount": 
     725                            if($this->invoicerecord[$column->fieldname]) 
     726                                $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     727                            break; 
     728 
     729                        default: 
     730                            $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     731 
     732                    }//endswitch 
     733 
     734            }//endif 
     735 
     736            $pdf->setStyle("normal"); 
     737            $pdf->SetFont("Arial", "B", 10); 
     738            $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
     739 
     740            foreach($this->totalsinfo as $column){ 
     741 
     742                    if($column->format != "") 
     743                            $value = formatVariable($this->invoicerecord[$column->fieldname], $column->format); 
     744                    else 
     745                            $value = $this->invoicerecord[$column->fieldname]; 
     746 
     747                    switch($column->fieldname){ 
     748                            case "shipping": 
     749                            case "discountamount": 
     750                                    if($this->invoicerecord[$column->fieldname]) 
     751                                            $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     752                                    break; 
     753                            default: 
     754                                    $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     755                    }//endswitch 
     756            }//end foreach 
     757            $this->totalsinfo[1]->size = 0; 
     758 
     759            $pdf->SetXY($pdf->leftmargin, $nextPos); 
     760 
     761    }//end method 
     762 
     763 
     764    function _addPaymentDetails(){ 
     765    }//end method 
     766 
     767 
     768    function output($destination = "screen" , $userinfo = NULL){ 
     769 
     770            switch($destination){ 
     771 
     772                    case "screen": 
     773                            $userinfo = cleanFilename((string)$userinfo); 
     774                            $this->pdf->Output($userinfo, 'D'); 
     775                            break; 
     776 
     777                    case "email": 
     778 
     779                            if(!$userinfo) 
     780                                    $userinfo = $_SESSION["userinfo"]; 
     781 
     782                            if(!$userinfo["email"] || !$this->invoicerecord["email"]) 
     783                                    return false; 
     784 
     785                            $pdf = $this->pdf->Output(NULL, "S"); 
     786 
     787                            $to =               $this->invoicerecord["email"]; 
     788                            $from =     $userinfo["email"]; 
     789                            $subject =  "Your ".$this->title." from ".COMPANY_NAME; 
     790                            $message =  "Attached is your ".$this->title." from ".COMPANY_NAME."\n\n" . 
     791                                                    "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . 
     792                                                    "have Acrobat Reader, you can download it at http://www.adobe.com  \n\n" . 
     793                                                    COMPANY_NAME."\n". 
     794                                                    COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; 
     795 
     796                            $headers = "From: $from"; 
     797 
     798                            $semi_rand = md5( time() ); 
     799                            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
     800 
     801                            $headers .= "\nMIME-Version: 1.0\n" . 
     802                                                    "Content-Type: multipart/mixed;\n" . 
     803                                                    " boundary=\"{$mime_boundary}\""; 
     804 
     805                            $message = "This is a multi-part message in MIME format.\n\n" . 
     806                                            "--{$mime_boundary}\n" . 
     807                                            "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
     808                                            "Content-Transfer-Encoding: 7bit\n\n" . 
     809                                            $message . "\n\n"; 
     810 
     811                            $pdf = chunk_split( base64_encode( $pdf ) ); 
     812 
     813                            $message .= "--{$mime_boundary}\n" . 
     814                                             "Content-Type: {application/pdf};\n" . 
     815                                             " name=\"".$this->title.$this->invoicerecord["id"].".pdf\"\n" . 
     816                                             "Content-Disposition: attachment;\n" . 
     817                                             " filename=\"".$this->title.$this->invoicerecord["id"].".pdf\"\n" . 
     818                                             "Content-Transfer-Encoding: base64\n\n" . 
     819                                             $pdf . "\n\n" . 
     820                                             "--{$mime_boundary}--\n"; 
     821 
     822                            return @ mail($to, $subject, $message, $headers); 
     823 
     824                            break; 
     825 
     826            }//endswitch 
     827 
     828    }//end method 
     829 
     830 
     831    /** 
     832     * function addingRecordDefaultSettings 
     833     * 
     834     * Creates an array of settings associative arrays for use by the system when 
     835     * a new report record is added that references the file containing this class 
     836     * 
     837     * @retrun array of settings. Each setting should itself be 
     838     * an associative array containing the following 
     839     * name: name of the setting 
     840     * defaultvalue: default value for setting 
     841     * type: (string, int, real, bool) type for value of setting 
     842     * required: (0,1) whether the setting is required or not 
     843     * description: brief description for what this setting is used for. 
     844     */ 
     845    function addingRecordDefaultSettings(){ 
     846 
     847        $settings[] = array( 
     848            "name"=>"reportTitle", 
     849            "defaultValue"=>"Invoice", 
     850            "type"=>"string", 
     851            "required"=>1, 
     852            "description"=>"Title printed on reports" 
     853        ); 
     854 
     855        $settings[] = array( 
     856            "name"=>"printLogo", 
     857            "defaultValue"=>1, 
     858            "type"=>"bool", 
     859            "required"=>1, 
     860            "description"=>"Should the logo print (1 = yes, 0 = no)" 
     861        ); 
     862 
     863        $settings[] = array( 
     864            "name"=>"printCompanyInfo", 
     865            "defaultValue"=>1, 
     866            "type"=>"bool", 
     867            "required"=>1, 
     868            "description"=>"Should the top company information print (1 = yes, 0 = no)" 
     869        ); 
     870 
     871        $settings[] = array( 
     872            "name"=>"leftTopBox", 
     873            "defaultValue"=>"billto", 
     874            "type"=>"string", 
     875            "required"=>1, 
     876            "description"=>"Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)" 
     877        ); 
     878 
     879        $settings[] = array( 
     880            "name"=>"leftTopBoxTitle", 
     881            "defaultValue"=>"SOLD TO", 
     882            "type"=>"string", 
     883            "required"=>1, 
     884            "description"=>"Title of Left Top Header Box" 
     885        ); 
     886 
     887        $settings[] = array( 
     888            "name"=>"rightTopBox", 
     889            "defaultValue"=>"shipto", 
     890            "type"=>"string", 
     891            "required"=>1, 
     892            "description"=>"Contents of Right Top Header Box (can be `billto`, `shipto`, `invoiceinfo`, `companyinfo`, `nowshow` or `blank`)" 
     893        ); 
     894 
     895        $settings[] = array( 
     896            "name"=>"rightTopBoxTitle", 
     897            "defaultValue"=>"SHIP TO", 
     898            "type"=>"string", 
     899            "required"=>1, 
     900            "description"=>"Title of Right Top Header Box" 
     901        ); 
     902 
     903        $settings[] = array( 
     904            "name"=>"templateFormatting", 
     905            "defaultValue"=>"0", 
     906            "type"=>"bool", 
     907            "required"=>1, 
     908            "description"=>"Should PDF remove lines and dark titles (1 = remove, 0 = keep)" 
     909        ); 
     910 
     911        $settings[] = array( 
     912            "name"=>"templateUUID", 
     913            "defaultValue"=>"", 
     914            "type"=>"string", 
     915            "required"=>0, 
     916            "description"=>"Optional UUID of file record for PDF to be used as background template" 
     917        ); 
     918 
     919        return $settings; 
     920 
     921    }//endfunction addingRecordDefaultSettings 
     922 
     923}//end class 
    676924 
    677925 
  • trunk/phpbms/modules/bms/report/invoices_totals.php

    r611 r693  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39  
    40 require("../../../include/session.php"); 
    41  
    42 class totalReport{ 
    43  
    44         var $selectcolumns; 
    45         var $selecttable; 
    46         var $whereclause=""; 
    47         var $group=""; 
    48         var $showinvoices=false; 
    49         var $showlineitems=false; 
    50         var $padamount=20; 
    51  
    52         function totalReport($db,$variables = NULL){ 
    53                 $this->db = $db; 
    54  
    55                 // first we define the available groups 
    56                 $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //0 
    57                 $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //1 
    58                 $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //2 
    59                 $this->addGroup("Invoice Date","invoices.invoicedate","date"); //3 
    60  
    61                 $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //4 
    62                 $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//5 
    63                 $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//6 
    64                 $this->addGroup("Order Date","invoices.orderdate","date");//7 
    65  
    66                 $this->addGroup("Required Date - Year","YEAR(invoices.requireddate)");//8 
    67                 $this->addGroup("Required Date - Quarter","QUARTER(invoices.requireddate)");//9 
    68                 $this->addGroup("Required Date - Month","MONTH(invoices.requireddate)");//10 
    69                 $this->addGroup("Required Date","invoices.requireddate","date");//11 
    70  
    71                 $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//12 
    72  
    73                 $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.uuid");//13 
    74  
    75                 $this->addGroup("Client Lead Source","clients.leadsource");//14 
    76  
    77                 $this->addGroup("Invoice Lead Source","invoices.leadsource");//15 
    78  
    79                 $this->addGroup("Payment Method","paymentmethods.name");//16 
    80  
    81                 $this->addGroup("Shipping Method","shippingmethods.name");//17 
    82                 $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//18 
    83                 $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//19 
    84                 $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//20 
    85                 $this->addGroup("Invoice Shipping City","invoices.shiptocity");//21 
    86  
    87                 $this->addGroup("Web Order","invoices.weborder","boolean");//22 
    88  
    89                 $this->addGroup("Invoice billing Country","invoices.country");//23 
    90                 $this->addGroup("Invoice Billing State / Province","invoices.state");//24 
    91                 $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//25 
    92                 $this->addGroup("Invoice Billing City","invoices.city");//26 
    93  
    94  
    95                 //next we do the columns 
    96                 $this->addColumn("Record Count","count(invoices.id)");//0 
    97                 $this->addColumn("Invoice Total","sum(invoices.totalti)","currency");//1 
    98                 $this->addColumn("Average Invoice Total","avg(invoices.totalti)","currency");//2 
    99  
    100                 $this->addColumn("Subtotal","sum(invoices.totaltni)","currency");//3 
    101                 $this->addColumn("Average Subtotal","avg(invoices.totaltni)","currency");//4 
    102  
    103                 $this->addColumn("Tax","sum(invoices.tax)","currency");//5 
    104                 $this->addColumn("Average Tax","avg(invoices.tax)","currency");//6 
    105  
    106                 $this->addColumn("Shipping","sum(invoices.shipping)","currency");//7 
    107                 $this->addColumn("Average Shipping","avg(invoices.shipping)","currency");//8 
    108  
    109                 $this->addColumn("Amount Paid","sum(invoices.amountpaid)","currency");//9 
    110                 $this->addColumn("Average Amount Paid","avg(invoices.amountpaid)","currency");//10 
    111  
    112                 $this->addColumn("Amount Due","sum(invoices.totalti - invoices.amountpaid)","currency");//11 
    113                 $this->addColumn("Average Amount Due","avg(invoices.totalti - invoices.amountpaid)","currency");//12 
    114  
    115                 $this->addColumn("Cost","sum(invoices.totalcost)","currency");//13 
    116                 $this->addColumn("Average Cost","avg(invoices.totalcost)","currency");//14 
    117  
    118                 $this->addColumn("Total Weight","sum(invoices.totalweight)","real");//15 
    119                 $this->addColumn("Average Total Weight","avg(invoices.totalweight)","real");//16 
    120  
    121  
    122                 if($variables){ 
    123                         $tempArray = explode("::", $variables["columns"]); 
    124  
    125                         foreach($tempArray as $id) 
    126                                 $this->selectcolumns[] = $this->columns[$id]; 
    127                         $this->selectcolumns = array_reverse($this->selectcolumns); 
    128  
    129                         $this->selecttable="((`invoices` INNER JOIN `clients` ON `invoices`.`clientid`=`clients`.`uuid`) LEFT JOIN `shippingmethods` ON `shippingmethods`.`uuid` = `invoices`.`shippingmethodid`) LEFT JOIN `paymentmethods` ON `paymentmethods`.`id`=`invoices`.`paymentmethodid`"; 
    130  
    131                         if($variables["groupings"] !== ""){ 
    132                                 $this->group = explode("::",$variables["groupings"]); 
    133                                 $this->group = array_reverse($this->group); 
    134                         } else 
    135                                 $this->group = array(); 
    136  
    137                         foreach($this->group as $grp){ 
    138                                 if($this->groupings[$grp]["table"]) 
    139                                         $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
    140                         } 
    141  
    142                         $this->whereclause=$_SESSION["printing"]["whereclause"]; 
    143                         if($this->whereclause=="") $this->whereclause="WHERE invoices.id!=-1"; 
    144  
    145                         switch($variables["showwhat"]){ 
    146                                 case "invoices": 
    147                                         $this->showinvoices = true; 
    148                                         $this->showlineitems = false; 
    149                                         break; 
    150  
    151                                 case "lineitems": 
    152                                         $this->showinvoices = true; 
    153                                         $this->showlineitems = true; 
    154                                         break; 
    155  
    156                                 default: 
    157                                         $this->showinvoices = false; 
    158                                         $this->showlineitems = false; 
    159                         }// endswitch 
    160  
    161                         if($this->whereclause!="") $this->whereclause=" WHERE (".substr($this->whereclause,6).") "; 
    162                 }// endif 
     39if(!class_exists("phpbmsReport")) 
     40    include("../../../report/report_class.php"); 
     41 
     42class totalReport extends phpbmsReport{ 
     43 
     44    var $selectcolumns; 
     45    var $selecttable; 
     46    var $group = ""; 
     47    var $showinvoices = false; 
     48    var $showlineitems = false; 
     49    var $padamount = 20; 
     50    var $title = "Totals"; 
     51 
     52        function totalReport($db, $reportUUID, $tabledefUUID, $variables = NULL){ 
     53 
     54            parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     55 
     56            // first we define the available groups 
     57            $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //0 
     58            $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //1 
     59            $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //2 
     60            $this->addGroup("Invoice Date","invoices.invoicedate","date"); //3 
     61 
     62            $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //4 
     63            $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//5 
     64            $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//6 
     65            $this->addGroup("Order Date","invoices.orderdate","date");//7 
     66 
     67            $this->addGroup("Required Date - Year","YEAR(invoices.requireddate)");//8 
     68            $this->addGroup("Required Date - Quarter","QUARTER(invoices.requireddate)");//9 
     69            $this->addGroup("Required Date - Month","MONTH(invoices.requireddate)");//10 
     70            $this->addGroup("Required Date","invoices.requireddate","date");//11 
     71 
     72            $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//12 
     73 
     74            $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.uuid");//13 
     75 
     76            $this->addGroup("Client Lead Source","clients.leadsource");//14 
     77 
     78            $this->addGroup("Invoice Lead Source","invoices.leadsource");//15 
     79 
     80            $this->addGroup("Payment Method","paymentmethods.name");//16 
     81 
     82            $this->addGroup("Shipping Method","shippingmethods.name");//17 
     83            $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//18 
     84            $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//19 
     85            $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//20 
     86            $this->addGroup("Invoice Shipping City","invoices.shiptocity");//21 
     87 
     88            $this->addGroup("Web Order","invoices.weborder","boolean");//22 
     89 
     90            $this->addGroup("Invoice billing Country","invoices.country");//23 
     91            $this->addGroup("Invoice Billing State / Province","invoices.state");//24 
     92            $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//25 
     93            $this->addGroup("Invoice Billing City","invoices.city");//26 
     94 
     95 
     96            //next we do the columns 
     97            $this->addColumn("Record Count","count(invoices.id)");//0 
     98            $this->addColumn("Invoice Total","sum(invoices.totalti)","currency");//1 
     99            $this->addColumn("Average Invoice Total","avg(invoices.totalti)","currency");//2 
     100 
     101            $this->addColumn("Subtotal","sum(invoices.totaltni)","currency");//3 
     102            $this->addColumn("Average Subtotal","avg(invoices.totaltni)","currency");//4 
     103 
     104            $this->addColumn("Tax","sum(invoices.tax)","currency");//5 
     105            $this->addColumn("Average Tax","avg(invoices.tax)","currency");//6 
     106 
     107            $this->addColumn("Shipping","sum(invoices.shipping)","currency");//7 
     108            $this->addColumn("Average Shipping","avg(invoices.shipping)","currency");//8 
     109 
     110            $this->addColumn("Amount Paid","sum(invoices.amountpaid)","currency");//9 
     111            $this->addColumn("Average Amount Paid","avg(invoices.amountpaid)","currency");//10 
     112 
     113            $this->addColumn("Amount Due","sum(invoices.totalti - invoices.amountpaid)","currency");//11 
     114            $this->addColumn("Average Amount Due","avg(invoices.totalti - invoices.amountpaid)","currency");//12 
     115 
     116            $this->addColumn("Cost","sum(invoices.totalcost)","currency");//13 
     117            $this->addColumn("Average Cost","avg(invoices.totalcost)","currency");//14 
     118 
     119            $this->addColumn("Total Weight","sum(invoices.totalweight)","real");//15 
     120            $this->addColumn("Average Total Weight","avg(invoices.totalweight)","real");//16 
     121 
     122            $this->selecttable="((`invoices` INNER JOIN `clients` ON `invoices`.`clientid`=`clients`.`uuid`) 
     123                                LEFT JOIN `shippingmethods` ON `shippingmethods`.`uuid` = `invoices`.`shippingmethodid`) 
     124                                LEFT JOIN `paymentmethods` ON `paymentmethods`.`id`=`invoices`.`paymentmethodid`"; 
     125 
    163126        }//end method 
    164127 
    165128 
     129        function processFromPost($variables){ 
     130 
     131            $tempArray = explode("::", $variables["columns"]); 
     132 
     133            foreach($tempArray as $id) 
     134                $this->selectcolumns[] = $this->columns[$id]; 
     135 
     136            $this->selectcolumns = array_reverse($this->selectcolumns); 
     137 
     138            if($variables["groupings"] !== ""){ 
     139 
     140                $this->group = explode("::",$variables["groupings"]); 
     141                $this->group = array_reverse($this->group); 
     142 
     143            } else 
     144                $this->group = array(); 
     145 
     146            foreach($this->group as $grp) 
     147                if($this->groupings[$grp]["table"]) 
     148                    $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
     149 
     150            switch($variables["showwhat"]){ 
     151 
     152                case "invoices": 
     153                    $this->showinvoices = true; 
     154                    $this->showlineitems = false; 
     155                    break; 
     156 
     157                case "lineitems": 
     158                    $this->showinvoices = true; 
     159                    $this->showlineitems = true; 
     160                    break; 
     161 
     162                default: 
     163                    $this->showinvoices = false; 
     164                    $this->showlineitems = false; 
     165 
     166            }// endswitch 
     167 
     168            if($variables["reporttitle"]) 
     169                $this->title = $variables["reporttitle"]; 
     170 
     171        }//end function processFromPost 
     172 
     173 
     174        function processFromSettings(){ 
     175 
     176            foreach($this->settings as $key=>$value) 
     177                if(strpos($key, "column") === 0) 
     178                    $this->selectcolumns[substr($key,6)-1] = $this->columns[$value]; 
     179 
     180            ksort($this->selectcolumns); 
     181            $this->selectcolumns = array_reverse($this->selectcolumns); 
     182 
     183            $this->group = array(); 
     184 
     185            foreach($this->settings as $key=>$value) 
     186                if(strpos($key, "group") === 0) 
     187                    $this->group[substr($key,5)-1] = $value; 
     188 
     189            ksort($this->group); 
     190            $this->group = array_reverse($this->group); 
     191 
     192            foreach($this->group as $grp) 
     193                if($this->groupings[$grp]["table"]) 
     194                    $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
     195 
     196 
     197            if(isset($this->settings["showWhat"])) 
     198                $showWhat = $this->settings["showWhat"]; 
     199            else 
     200                $showWhat = ""; 
     201 
     202            switch($showWhat){ 
     203 
     204                case "invoices": 
     205                    $this->showinvoices = true; 
     206                    $this->showlineitems = false; 
     207                    break; 
     208 
     209                case "lineitems": 
     210                    $this->showinvoices = true; 
     211                    $this->showlineitems = true; 
     212                    break; 
     213 
     214                default: 
     215                    $this->showinvoices = false; 
     216                    $this->showlineitems = false; 
     217 
     218            }// endswitch 
     219 
     220            if(isset($this->settings["reportTitle"])) 
     221                $this->title = $this->settings["reportTitle"]; 
     222 
     223        }//end function processFromSettings 
     224 
     225 
    166226        function addGroup($name, $field, $format = NULL, $tableAddition = NULL){ 
    167                 $temp = array(); 
    168                 $temp["name"] = $name; 
    169                 $temp["field"] = $field; 
    170                 $temp["format"] = $format; 
    171                 $temp["table"] = $tableAddition; 
    172  
    173                 $this->groupings[] = $temp; 
     227 
     228            $temp = array(); 
     229            $temp["name"] = $name; 
     230            $temp["field"] = $field; 
     231            $temp["format"] = $format; 
     232            $temp["table"] = $tableAddition; 
     233 
     234            $this->groupings[] = $temp; 
     235 
    174236        }//end method 
    175237 
    176238 
    177239        function addColumn($name, $field, $format = NULL){ 
    178                 $temp = array(); 
    179                 $temp["name"] = $name; 
    180                 $temp["field"] = $field; 
    181                 $temp["format"] = $format; 
    182  
    183                 $this->columns[] = $temp; 
     240 
     241            $temp = array(); 
     242            $temp["name"] = $name; 
     243            $temp["field"] = $field; 
     244            $temp["format"] = $format; 
     245 
     246            $this->columns[] = $temp; 
     247 
    184248        }//end method 
    185249 
    186250 
    187251        function showReportTable(){ 
     252 
    188253                ?><table border="0" cellspacing="0" cellpadding="0"> 
    189254                <tr> 
     
    207272                        $querystatement.=$thecolumn["field"]." AS `".$thecolumn["name"]."`,"; 
    208273                $querystatement.=" count(invoices.id) as thecount "; 
    209                 $querystatement.=" FROM ".$this->selecttable.$this->whereclause; 
     274                $querystatement.=" FROM ".$this->selecttable.$this->whereClause; 
    210275                $queryresult=$this->db->query($querystatement); 
    211276 
     
    236301                                $querystatement.=$thecolumn["field"]." AS `".$thecolumn["name"]."`,"; 
    237302                        $querystatement .= $this->groupings[$groupby]["field"]." AS thegroup, count(invoices.id) as thecount "; 
    238                         $querystatement .= " FROM ".$this->selecttable.$this->whereclause.$where." GROUP BY ".$this->groupings[$groupby]["field"]; 
     303                        $querystatement .= " FROM ".$this->selecttable.$this->whereClause.$where." GROUP BY ".$this->groupings[$groupby]["field"]; 
    239304                        $queryresult=$this->db->query($querystatement); 
    240305 
     
    288353                $querystatement.=" invoices.id as theid, if(clients.lastname!=\"\",concat(clients.lastname,\", \",clients.firstname,if(clients.company!=\"\",concat(\" (\",clients.company,\")\"),\"\")),clients.company) as thename, 
    289354                                                        invoices.orderdate,invoices.invoicedate"; 
    290                 $querystatement.=" FROM ".$this->selecttable.$this->whereclause.$where." GROUP BY invoices.id"; 
     355                $querystatement.=" FROM ".$this->selecttable.$this->whereClause.$where." GROUP BY invoices.id"; 
    291356                $queryresult=$this->db->query($querystatement); 
    292357 
     
    370435        function showReport(){ 
    371436 
    372                 if($_POST["reporttitle"]) 
    373                         $pageTitle = $_POST["reporttitle"]; 
    374                 else 
    375                         $pageTitle = "Invoice Totals"; 
    376  
     437            if(!$this->whereClause) 
     438                $this->whereClause = "invoices.id!=-1"; 
     439 
     440            $this->whereClause = " WHERE ".$this->whereClause; 
     441 
     442            $pageTitle = $this->title; 
    377443 
    378444?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    427493        <div class="bodyline"> 
    428494            <h1>Invoice Total Options</h1> 
    429             <form id="GroupForm" action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="GroupForm"> 
     495            <form id="GroupForm" action="<?php echo str_replace("&", "&amp;", $_SERVER["REQUEST_URI"]) ?>" method="post" name="GroupForm"> 
    430496 
    431497                <fieldset> 
     
    495561    }//end method 
    496562 
    497 }//endclass 
    498  
    499 // Processing =================================================================================================================== 
    500 if(!isset($dontProcess)){ 
    501         if(isset($_POST["columns"])){ 
    502                 $myreport= new totalReport($db,$_POST); 
    503                 $myreport->showReport(); 
    504         } else { 
    505                 $myreport = new totalReport($db); 
    506                 $myreport->showSelectScreen(); 
    507         } 
    508 }?> 
     563}//end class totalReport 
     564 
     565 
     566/** 
     567 * PROCESSING 
     568 * ============================================================================= 
     569 */ 
     570if(!isset($noOutput)){ 
     571 
     572    require("../../../include/session.php"); 
     573 
     574    checkForReportArguments(); 
     575 
     576    $report = new totalReport($db, $_GET["rid"], $_GET["tid"]); 
     577 
     578    if(isset($_POST["columns"])){ 
     579 
     580        $report->setupFromPrintScreen(); 
     581        $report->processFromPost($_POST); 
     582        $report->showReport(); 
     583 
     584    } elseif(isset($report->settings["column1"])){ 
     585 
     586        $report->setupFromPrintScreen(); 
     587        $report->processFromSettings(); 
     588        $report->showReport(); 
     589 
     590    } else { 
     591 
     592        $report->showSelectScreen(); 
     593 
     594    }//endif 
     595 
     596}//endif 
     597 
     598/** 
     599 * When adding a new report record, the add/edit needs to know what the class 
     600 * name is so that it can instantiate it, and grab it's default settings. 
     601 */ 
     602if(isset($addingReportRecord)) 
     603    $reportClass ="totalReport"; 
     604 
     605?> 
  • trunk/phpbms/modules/bms/report/lineitems_totals.php

    r611 r693  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39  
    40 require("../../../include/session.php"); 
    41  
    42 class totalReport{ 
     39if(!class_exists("phpbmsReport")) 
     40    include("../../../report/report_class.php"); 
     41 
     42class totalReport extends phpbmsReport{ 
    4343 
    4444        var $selectcolumns; 
    4545        var $selecttable; 
    46         var $whereclause=""; 
    47         var $group=""; 
    48         var $showinvoices=false; 
    49         var $showlineitems=false; 
    50         var $padamount=20; 
    51  
    52         function totalReport($db,$variables = NULL){ 
    53                 $this->db = $db; 
    54  
    55                 // first we define the available groups 
    56                 $this->addGroup("Invoice ID","invoices.id"); //0 
    57                 $this->addGroup("Product","concat(products.partnumber,' - ',products.partname)"); //1 
    58                 $this->addGroup("Product Category","concat(productcategories.id,' - ',productcategories.name)",NULL,"INNER JOIN productcategories ON products.categoryid=productcategories.uuid"); //2 
    59  
    60                 $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //3 
    61                 $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //4 
    62                 $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //5 
    63                 $this->addGroup("Invoice Date","invoices.invoicedate","date"); //6 
    64  
    65                 $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //7 
    66                 $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//8 
    67                 $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//9 
    68                 $this->addGroup("Order Date","invoices.orderdate","date");//10 
    69  
    70                 $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//11 
    71  
    72                 $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.id");//12 
    73  
    74                 $this->addGroup("Client Lead Source","clients.leadsource");//13 
    75  
    76                 $this->addGroup("Invoice Lead Source","invoices.leadsource");//14 
    77  
    78                 $this->addGroup("Payment Method","paymentmethods.name");//15 
    79  
    80                 $this->addGroup("Shipping Method","shippingmethods.name");//16 
    81                 $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//17 
    82                 $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//18 
    83                 $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//19 
    84                 $this->addGroup("Invoice Shipping City","invoices.shiptocity");//20 
    85  
    86                 $this->addGroup("Web Order","invoices.weborder","boolean");//21 
    87  
    88                 $this->addGroup("Invoice billing Country","invoices.country");//22 
    89                 $this->addGroup("Invoice Billing State / Province","invoices.state");//23 
    90                 $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//24 
    91                 $this->addGroup("Invoice Billing City","invoices.city");//25 
    92  
    93                 //next we do the columns 
    94                 $this->addColumn("Record Count","count(lineitems.id)");//0 
    95                 $this->addColumn("Extended Price","sum(lineitems.unitprice*lineitems.quantity)","currency");//1 
    96                 $this->addColumn("Average Extended Price","avg(lineitems.unitprice*lineitems.quantity)","currency");//2 
    97                 $this->addColumn("Unit Price","sum(lineitems.unitprice)","currency");//3 
    98                 $this->addColumn("Average Unit Price","avg(lineitems.unitprice)","currency");//4 
    99                 $this->addColumn("Quantity","sum(lineitems.quantity)","real");//5 
    100                 $this->addColumn("Average Quantity","avg(lineitems.quantity)","real");//6 
    101                 $this->addColumn("Unit Cost","sum(lineitems.unitcost)","currency");//7 
    102                 $this->addColumn("Average Unit Cost","avg(lineitems.unitcost)","currency");//8 
    103                 $this->addColumn("Extended Cost","sum(lineitems.unitcost*lineitems.quantity)","currency");//9 
    104                 $this->addColumn("Average Extended Cost","avg(lineitems.unitcost*lineitems.quantity)","currency");//10 
    105                 $this->addColumn("Unit Weight","sum(lineitems.unitweight)","real");//11 
    106                 $this->addColumn("Average Unit Weight","avg(lineitems.unitweight)","real");//12 
    107                 $this->addColumn("Extended Unit Weight","sum(lineitems.unitweight*lineitems.quantity)","real");//13 
    108                 $this->addColumn("Extended Average Unit Weight","avg(lineitems.unitweight*lineitems.quantity)","real");//14 
    109  
    110  
    111                 if($variables){ 
    112                         $tempArray = explode("::", $variables["columns"]); 
    113  
    114                         foreach($tempArray as $id) 
    115                                 $this->selectcolumns[] = $this->columns[$id]; 
    116                         $this->selectcolumns = array_reverse($this->selectcolumns); 
    117  
    118                         //change 
    119                         $this->selecttable="(((((lineitems LEFT JOIN products ON lineitems.productid=products.uuid) 
    120                                                                         INNER JOIN invoices ON lineitems.invoiceid=invoices.id) 
    121                                                                         INNER JOIN clients ON invoices.clientid=clients.uuid) 
    122                                                                         LEFT JOIN shippingmethods ON shippingmethods.uuid=invoices.shippingmethodid) 
    123                                                                         LEFT JOIN paymentmethods ON paymentmethods.uuid=invoices.paymentmethodid) 
    124                                                                         "; 
    125  
    126                         if($variables["groupings"] !== ""){ 
    127                                 $this->group = explode("::",$variables["groupings"]); 
    128                                 $this->group = array_reverse($this->group); 
    129                         } else 
    130                                 $this->group = array(); 
    131  
    132                         foreach($this->group as $grp){ 
    133                                 if($this->groupings[$grp]["table"]) 
    134                                         $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
    135                         } 
    136  
    137                         $this->whereclause=$_SESSION["printing"]["whereclause"]; 
    138                         if($this->whereclause=="") $this->whereclause="WHERE invoices.id!=-1"; 
    139  
    140                         switch($variables["showwhat"]){ 
    141                                 case "invoices": 
    142                                         $this->showinvoices = true; 
    143                                         $this->showlineitems = false; 
    144                                         break; 
    145  
    146                                 case "lineitems": 
    147                                         $this->showinvoices = true; 
    148                                         $this->showlineitems = true; 
    149                                         break; 
    150  
    151                                 default: 
    152                                         $this->showinvoices = false; 
    153                                         $this->showlineitems = false; 
    154                         }// endswitch 
    155  
    156                         if($this->whereclause!="") $this->whereclause=" WHERE (".substr($this->whereclause,6).") "; 
    157                 }// endif 
     46        var $group = ""; 
     47        var $showinvoices = false; 
     48        var $showlineitems = false; 
     49        var $padamount = 20; 
     50        var $title = "Totals"; 
     51 
     52        function totalReport($db, $reportUUID, $tabledefUUID, $variables = NULL){ 
     53 
     54            parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     55 
     56            // first we define the available groups 
     57            $this->addGroup("Invoice ID","invoices.id"); //0 
     58            $this->addGroup("Product","concat(products.partnumber,' - ',products.partname)"); //1 
     59            $this->addGroup("Product Category","concat(productcategories.id,' - ',productcategories.name)",NULL,"INNER JOIN productcategories ON products.categoryid=productcategories.uuid"); //2 
     60 
     61            $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //3 
     62            $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //4 
     63            $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //5 
     64            $this->addGroup("Invoice Date","invoices.invoicedate","date"); //6 
     65 
     66            $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //7 
     67            $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//8 
     68            $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//9 
     69            $this->addGroup("Order Date","invoices.orderdate","date");//10 
     70 
     71            $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//11 
     72 
     73            $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.id");//12 
     74 
     75            $this->addGroup("Client Lead Source","clients.leadsource");//13 
     76 
     77            $this->addGroup("Invoice Lead Source","invoices.leadsource");//14 
     78 
     79            $this->addGroup("Payment Method","paymentmethods.name");//15 
     80 
     81            $this->addGroup("Shipping Method","shippingmethods.name");//16 
     82            $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//17 
     83            $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//18 
     84            $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//19 
     85            $this->addGroup("Invoice Shipping City","invoices.shiptocity");//20 
     86 
     87            $this->addGroup("Web Order","invoices.weborder","boolean");//21 
     88 
     89            $this->addGroup("Invoice billing Country","invoices.country");//22 
     90            $this->addGroup("Invoice Billing State / Province","invoices.state");//23 
     91            $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//24 
     92            $this->addGroup("Invoice Billing City","invoices.city");//25 
     93 
     94            //next we do the columns 
     95            $this->addColumn("Record Count","count(lineitems.id)");//0 
     96            $this->addColumn("Extended Price","sum(lineitems.unitprice*lineitems.quantity)","currency");//1 
     97            $this->addColumn("Average Extended Price","avg(lineitems.unitprice*lineitems.quantity)","currency");//2 
     98            $this->addColumn("Unit Price","sum(lineitems.unitprice)","currency");//3 
     99            $this->addColumn("Average Unit Price","avg(lineitems.unitprice)","currency");//4 
     100            $this->addColumn("Quantity","sum(lineitems.quantity)","real");//5 
     101            $this->addColumn("Average Quantity","avg(lineitems.quantity)","real");//6 
     102            $this->addColumn("Unit Cost","sum(lineitems.unitcost)","currency");//7 
     103            $this->addColumn("Average Unit Cost","avg(lineitems.unitcost)","currency");//8 
     104            $this->addColumn("Extended Cost","sum(lineitems.unitcost*lineitems.quantity)","currency");//9 
     105            $this->addColumn("Average Extended Cost","avg(lineitems.unitcost*lineitems.quantity)","currency");//10 
     106            $this->addColumn("Unit Weight","sum(lineitems.unitweight)","real");//11 
     107            $this->addColumn("Average Unit Weight","avg(lineitems.unitweight)","real");//12 
     108            $this->addColumn("Extended Unit Weight","sum(lineitems.unitweight*lineitems.quantity)","real");//13 
     109            $this->addColumn("Extended Average Unit Weight","avg(lineitems.unitweight*lineitems.quantity)","real");//14 
     110 
     111            //change 
     112            $this->selecttable="(((((lineitems LEFT JOIN products ON lineitems.productid=products.uuid) 
     113                                                            INNER JOIN invoices ON lineitems.invoiceid=invoices.id) 
     114                                                            INNER JOIN clients ON invoices.clientid=clients.uuid) 
     115                                                            LEFT JOIN shippingmethods ON shippingmethods.uuid=invoices.shippingmethodid) 
     116                                                            LEFT JOIN paymentmethods ON paymentmethods.uuid=invoices.paymentmethodid) 
     117                                                            "; 
     118 
     119        }//end function totalReport 
     120 
     121 
     122        function processFromPost($variables){ 
     123 
     124            $tempArray = explode("::", $variables["columns"]); 
     125 
     126            foreach($tempArray as $id) 
     127                    $this->selectcolumns[] = $this->columns[$id]; 
     128 
     129            $this->selectcolumns = array_reverse($this->selectcolumns); 
     130 
     131            if($variables["groupings"] !== ""){ 
     132 
     133                $this->group = explode("::",$variables["groupings"]); 
     134                $this->group = array_reverse($this->group); 
     135 
     136            } else 
     137                $this->group = array(); 
     138 
     139            foreach($this->group as $grp) 
     140                if($this->groupings[$grp]["table"]) 
     141                    $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
     142 
     143            switch($variables["showwhat"]){ 
     144 
     145                case "invoices": 
     146                    $this->showinvoices = true; 
     147                    $this->showlineitems = false; 
     148                    break; 
     149 
     150                case "lineitems": 
     151                    $this->showinvoices = true; 
     152                    $this->showlineitems = true; 
     153                    break; 
     154 
     155                default: 
     156                    $this->showinvoices = false; 
     157                    $this->showlineitems = false; 
     158 
     159            }// endswitch 
     160 
     161            if($variables["reporttitle"]) 
     162                $this->title = $variables["reporttitle"]; 
     163 
     164        }//end function processFromPost 
     165 
     166 
     167        function processFromSettings(){ 
     168 
     169            foreach($this->settings as $key=>$value) 
     170                if(strpos($key, "column") === 0) 
     171                    $this->selectcolumns[substr($key,6)-1] = $this->columns[$value]; 
     172 
     173            ksort($this->selectcolumns); 
     174            $this->selectcolumns = array_reverse($this->selectcolumns); 
     175 
     176            $this->group = array(); 
     177 
     178            foreach($this->settings as $key=>$value) 
     179                if(strpos($key, "group") === 0) 
     180                    $this->group[substr($key,5)-1] = $value; 
     181 
     182            ksort($this->group); 
     183            $this->group = array_reverse($this->group); 
     184 
     185            foreach($this->group as $grp) 
     186                if($this->groupings[$grp]["table"]) 
     187                    $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; 
     188 
     189 
     190            if(isset($this->settings["showWhat"])) 
     191                $showWhat = $this->settings["showWhat"]; 
     192            else 
     193                $showWhat = ""; 
     194 
     195            switch($showWhat){ 
     196 
     197                case "invoices": 
     198                    $this->showinvoices = true; 
     199                    $this->showlineitems = false; 
     200                    break; 
     201 
     202                case "lineitems": 
     203                    $this->showinvoices = true; 
     204                    $this->showlineitems = true; 
     205                    break; 
     206 
     207                default: 
     208                    $this->showinvoices = false; 
     209                    $this->showlineitems = false; 
     210 
     211            }// endswitch 
     212 
     213            if(isset($this->settings["reportTitle"])) 
     214                $this->title = $this->settings["reportTitle"]; 
     215 
     216        }//end function processFromSettings 
     217 
     218 
     219        function addGroup($name, $field, $format = NULL, $tableAddition = NULL){ 
     220 
     221            $temp = array(); 
     222            $temp["name"] = $name; 
     223            $temp["field"] = $field; 
     224            $temp["format"] = $format; 
     225            $temp["table"] = $tableAddition; 
     226 
     227            $this->groupings[] = $temp; 
     228 
    158229        }//end method 
    159230 
    160231 
    161         function addGroup($name, $field, $format = NULL, $tableAddition = NULL){ 
    162                 $temp = array(); 
    163                 $temp["name"] = $name; 
    164                 $temp["field"] = $field; 
    165                 $temp["format"] = $format; 
    166                 $temp["table"] = $tableAddition; 
    167  
    168                 $this->groupings[] = $temp; 
     232        function addColumn($name, $field, $format = NULL){ 
     233 
     234            $temp = array(); 
     235            $temp["name"] = $name; 
     236            $temp["field"] = $field; 
     237            $temp["format"] = $format; 
     238 
     239            $this->columns[] = $temp; 
     240 
    169241        }//end method 
    170242 
    171243 
    172         function addColumn($name, $field, $format = NULL){ 
    173                 $temp = array(); 
    174                 $temp["name"] = $name; 
    175                 $temp["field"] = $field; 
    176                 $temp["format"] = $format; 
    177  
    178                 $this->columns[] = $temp; 
    179         }//end method 
    180  
    181  
    182244        function showReportTable(){ 
    183                 ?><table border="0" cellspacing="0" cellpadding="0"> 
    184                 <tr> 
    185                         <th>&nbsp;</th> 
    186                 <?php 
    187                         foreach($this->selectcolumns as $thecolumn){ 
    188                                 ?><th align="right"><?php echo $thecolumn["name"]?></th><?php 
    189                         }//end foreach 
    190                 ?> 
    191                 </tr> 
    192                 <?php $this->showGroup($this->group,"",10);?> 
    193                 <?php $this->showGrandTotals();?> 
    194                 </table> 
    195                 <?php 
    196         } 
     245 
     246            ?><table border="0" cellspacing="0" cellpadding="0"> 
     247            <tr> 
     248                    <th>&nbsp;</th> 
     249            <?php 
     250                    foreach($this->selectcolumns as $thecolumn){ 
     251                            ?><th align="right"><?php echo $thecolumn["name"]?></th><?php 
     252                    }//end foreach 
     253            ?> 
     254            </tr> 
     255            <?php $this->showGroup($this->group,"",10);?> 
     256            <?php $this->showGrandTotals();?> 
     257            </table> 
     258            <?php 
     259 
     260        }//end function showReportTable(); 
     261 
    197262 
    198263        function showGrandTotals(){ 
    199264 
    200                 $querystatement="SELECT "; 
    201                 foreach($this->selectcolumns as $thecolumn) 
    202                         $querystatement.=$thecolumn["field"]." AS `".$thecolumn["name"]."`,"; 
    203                 $querystatement.=" count(lineitems.id) as thecount "; 
    204                 $querystatement.=" FROM ".$this->selecttable.$this->whereclause; 
    205                 $queryresult=$this->db->query($querystatement); 
    206  
    207                 $therecord=$this->db->fetchArray($queryresult); 
    208                 ?> 
    209                 <tr> 
    210                         <td class="grandtotals" align="right">Totals: (<?php echo $therecord["thecount"]?>)</td> 
    211                         <?php 
    212                                 foreach($this->selectcolumns as $thecolumn){ 
    213                                         ?><td align="right" class="grandtotals"><?php echo formatVariable($therecord[$thecolumn["name"]],$thecolumn["format"])?></td><?php 
    214                                 }//end foreach 
    215                         ?> 
    216                 </tr> 
    217                 <?php 
    218         } 
     265            $querystatement="SELECT "; 
     266            foreach($this->selectcolumns as $thecolumn) 
     267                    $querystatement.=$thecolumn["field"]." AS `".$thecolumn["name"]."`,"; 
     268            $querystatement.=" count(lineitems.id) as thecount "; 
     269            $querystatement.=" FROM ".$this->selecttable.$this->whereClause; 
     270            $queryresult=$this->db->query($querystatement); 
     271 
     272            $therecord=$this->db->fetchArray($queryresult); 
     273            ?> 
     274            <tr> 
     275                    <td class="grandtotals" align="right">Totals: (<?php echo $therecord["thecount"]?>)</td> 
     276                    <?php 
     277                            foreach($this->selectcolumns as $thecolumn){ 
     278                                    ?><td align="right" class="grandtotals"><?php echo formatVariable($therecord[$thecolumn["name"]],$thecolumn["format"])?></td><?php 
     279                            }//end foreach 
     280                    ?> 
     281            </tr> 
     282            <?php 
     283 
     284        }//end function showGrandTotals 
     285 
    219286 
    220287        function showGroup($group,$where,$indent){ 
     
    231298                                $querystatement.=$thecolumn["field"]." AS `".$thecolumn["name"]."`,"; 
    232299                        $querystatement .= $this->groupings[$groupby]["field"]." AS thegroup, count(lineitems.id) as thecount "; 
    233                         $querystatement .= " FROM ".$this->selecttable.$this->whereclause.$where." GROUP BY ".$this->groupings[$groupby]["field"]; 
     300                        $querystatement .= " FROM ".$this->selecttable.$this->whereClause.$where." GROUP BY ".$this->groupings[$groupby]["field"]; 
    234301                        $queryresult=$this->db->query($querystatement); 
    235302 
     
    290357                                `lineitems`.`unitprice`, 
    291358                                `quantity`*`lineitems`.`unitprice` AS `extended` 
    292                         FROM ".$this->selecttable.$this->whereclause.$where." GROUP BY lineitems.id 
     359                        FROM ".$this->selecttable.$this->whereClause.$where." GROUP BY lineitems.id 
    293360                "; 
    294361 
     
    337404        function showReport(){ 
    338405 
    339                 if($_POST["reporttitle"]) 
    340                         $pageTitle = $_POST["reporttitle"]; 
    341                 else 
    342                         $pageTitle = "Line Item Totals"; 
    343  
     406            if(!$this->whereClause) 
     407                $this->whereClause = "invoices.id!=-1"; 
     408 
     409            $this->whereClause = " WHERE ".$this->whereClause; 
     410 
     411            $pageTitle = $this->title; 
    344412 
    345413?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    394462        <div class="bodyline"> 
    395463            <h1>Line Items Total Options</h1> 
    396             <form id="GroupForm" action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="GroupForm"> 
     464            <form id="GroupForm" action="<?php echo str_replace("&", "&amp;", $_SERVER["REQUEST_URI"]) ?>" method="post" name="GroupForm"> 
    397465 
    398466                <fieldset> 
     
    465533 
    466534 
    467 // Processing =================================================================================================================== 
    468 if(!isset($dontProcess)){ 
    469         if(isset($_POST["columns"])){ 
    470                 $myreport= new totalReport($db,$_POST); 
    471                 $myreport->showReport(); 
    472         } else { 
    473                 $myreport = new totalReport($db); 
    474                 $myreport->showSelectScreen(); 
    475         } 
    476 }?> 
     535/** 
     536 * PROCESSING 
     537 * ============================================================================= 
     538 */ 
     539if(!isset($noOutput)){ 
     540 
     541    require("../../../include/session.php"); 
     542 
     543    checkForReportArguments(); 
     544 
     545    $report = new totalReport($db, $_GET["rid"], $_GET["tid"]); 
     546 
     547    if(isset($_POST["columns"])){ 
     548 
     549        $report->setupFromPrintScreen(); 
     550        $report->processFromPost($_POST); 
     551        $report->showReport(); 
     552 
     553    } elseif(isset($report->settings["column1"])){ 
     554 
     555        $report->setupFromPrintScreen(); 
     556        $report->processFromSettings(); 
     557        $report->showReport(); 
     558 
     559    } else { 
     560 
     561        $report->showSelectScreen(); 
     562 
     563    }//endif 
     564 
     565}//endif 
     566 
     567/** 
     568 * When adding a new report record, the add/edit needs to know what the class 
     569 * name is so that it can instantiate it, and grab it's default settings. 
     570 */ 
     571if(isset($addingReportRecord)) 
     572    $reportClass ="totalReport"; 
     573 
     574?> 
  • trunk/phpbms/modules/bms/report/products_saleshistory.php

    r611 r693  
    3838*/ 
    3939 
    40 if(!isset($fromProduct)) { 
    41         require_once("../../../include/session.php"); 
    42 } 
    43  
    44 class salesHistoryReport{ 
     40if(!class_exists("phpbmsReport")) 
     41    include("../../../report/report_class.php"); 
     42 
     43class salesHistoryReport extends phpbmsReport{ 
     44 
     45    var $fromDate; 
     46    var $toDate; 
     47    var $view; 
     48    var $productQueryresult; 
     49    var $dataPrint; 
     50 
     51    function salesHistoryReport($db, $reportUUID, $tabledefUUID){ 
     52 
     53        parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     54 
     55        //$this->checkForDefaultSettings(); 
     56 
     57    }//end function init 
     58 
     59 
     60    function initialize($variables){ 
     61 
     62        if(!isset($variables["fromdate"]) || !isset($variables["todate"]) || !isset($variables["status"])) 
     63            $error = new appError(300, "Missing Passed Parameters"); 
     64 
     65        $this->fromDate = $variables["fromdate"]; 
     66        $this->toDate = $variables["todate"]; 
     67        $this->view = $variables["status"]; 
     68 
     69        $this->dataPrint = $_SESSION["printing"]["dataprint"]; 
     70 
     71        if(!$this->sortOrder) 
     72            $this->sortOrder = "  ORDER BY products.partnumber "; 
     73 
     74        if(!$this->whereClause) 
     75            $this->whereClause = "products.id!=-1"; 
     76 
     77        $this->whereClause = " WHERE (".$this->whereClause.") "; 
     78 
     79        $querystatement = " 
     80            SELECT 
     81                products.uuid, 
     82                products.partnumber, 
     83                products.partname 
     84            FROM 
     85                products 
     86            ".$this->whereClause.$this->sortOrder; 
     87 
     88        $this->productQueryresult = $this->db->query($querystatement); 
     89 
     90    }//end function initialize 
     91 
     92 
     93    function generateSingleHistory($productUUID){ 
     94 
     95        $theStatus = "(invoices.type = '"; 
     96 
     97        switch($this->view){ 
     98 
     99            case "Orders and Invoices": 
     100                $theStatus .= "Order' OR invoices.type ='Invoice')"; 
     101                $searchDate = "orderdate"; 
     102                break; 
     103 
     104            case "Invoices": 
     105                $theStatus .= "Invoice')"; 
     106                $searchDate = "invoicedate"; 
     107                break; 
     108 
     109            case "Orders": 
     110                $theStatus .= "Order')"; 
     111                $searchDate = "orderdate"; 
     112                break; 
     113 
     114        }//endswitch 
     115 
     116        $mysqlFromDate = sqlDateFromString($this->fromDate); 
     117        $mysqlToDate = sqlDateFromString($this->toDate); 
     118 
     119        $querystatement = " 
     120            SELECT 
     121                `invoices`.`id`, 
     122                `invoices`.`orderdate`, 
     123                `invoices`.`invoicedate`, 
     124                IF(clients.lastname!=\"\",concat(clients.lastname,\", \",clients.firstname,if(clients.company!=\"\",concat(\" (\",clients.company,\")\"),\"\")),clients.company) AS `client`, 
     125                `lineitems`.`quantity` AS `qty`, 
     126                `lineitems`.`unitprice`*`lineitems`.`quantity` AS `extended`, 
     127                `lineitems`.`unitprice` AS `price`, 
     128                `lineitems`.`unitcost` AS `cost`, 
     129                `lineitems`.`unitcost`*`lineitems`.`quantity` AS extendedcost 
     130            FROM 
     131                ((products INNER JOIN lineitems on products.uuid=lineitems.productid) 
     132                INNER JOIN `invoices` ON lineitems.invoiceid=invoices.id) 
     133                INNER JOIN `clients` on `invoices`.`clientid`=`clients`.`uuid` 
     134            WHERE 
     135                `products`.`uuid`='".$productUUID."' 
     136                AND 
     137                `invoices`.".$searchDate.">='".$mysqlFromDate."' 
     138                AND 
     139                `invoices`.".$searchDate."<='".$mysqlToDate."' 
     140                AND 
     141                ".$theStatus." 
     142            ORDER BY 
     143                `invoices`.`invoicedate`, 
     144                `invoices`.`orderdate` 
     145            "; 
     146 
     147        $queryresult = $this->db->query($querystatement); 
     148 
     149        ob_start(); 
     150 
     151        ?> 
     152        <table border="0" cellpadding="3" cellspacing="0"> 
     153            <thead> 
     154                <tr> 
     155                    <th align="center" nowrap="nowrap" >ID</th> 
     156                    <th align="center" nowrap="nowrap" >Order Date</th> 
     157                    <th align="center" nowrap="nowrap" >Invoice. Date</th> 
     158                    <th nowrap="nowrap"  width="100%" align="left">Client</th> 
     159                    <th align="center" nowrap="nowrap" >Qty.</th> 
     160                    <th align="right" nowrap="nowrap" >Unit Cost</th> 
     161                    <th align="right" nowrap="nowrap" >Cost Ext.</th> 
     162                    <th align="right" nowrap="nowrap" >Unit Price</th> 
     163                    <th align="right" nowrap="nowrap">Price Ext.</th> 
     164                </tr> 
     165            </thead> 
     166        <?php 
     167 
     168            $totalextended = 0; 
     169            $totalcostextended = 0; 
     170            $totalquantity = 0; 
     171            $avgprice = 0; 
     172            $avgcost = 0; 
     173 
     174            $numrows = $this->db->numRows($queryresult); 
     175 
     176            while ($therecord = $this->db->fetchArray($queryresult)){ 
     177 
     178                $avgcost += $therecord["cost"]; 
     179                $avgprice += $therecord["price"]; 
     180                $totalquantity += $therecord["qty"]; 
     181                $totalextended += $therecord["extended"]; 
     182                $totalcostextended += $therecord["extendedcost"]; 
     183        ?> 
     184            <tr> 
     185                <td align="center" nowrap="nowrap"><?php echo $therecord["id"]?></td> 
     186                <td align="center" nowrap="nowrap"><?php echo $therecord["orderdate"]?formatFromSQLDate($therecord["orderdate"]):"&nbsp;" ?></td> 
     187                <td align="center" nowrap="nowrap"><?php echo $therecord["invoicedate"]?formatFromSQLDate($therecord["invoicedate"]):"&nbsp;" ?></td> 
     188                <td nowrap="nowrap"><?php echo $therecord["client"]?></td> 
     189                <td align="center" nowrap="nowrap"><?php echo number_format($therecord["qty"],2)?></td> 
     190                <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["cost"])?></td> 
     191                <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extendedcost"])?></td> 
     192                <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["price"])?></td> 
     193                <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extended"])?></td> 
     194            </tr> 
     195          <?php }//endwhile ?> 
     196            <tr> 
     197                <td align="center" class="grandtotals">&nbsp;</td> 
     198                <td align="center" class="grandtotals">&nbsp;</td> 
     199                <td class="grandtotals">&nbsp;</td> 
     200                <td class="grandtotals">&nbsp;</td> 
     201                <td align="center" class="grandtotals"><?php echo number_format($totalquantity,2)?></td> 
     202                <td align="right" nowrap="nowrap"class="grandtotals">avg. = <?php $numrows?$avgcost=$avgcost/$numrows:$avgcost=0; echo numberToCurrency($avgcost)?></td> 
     203                <td align="right" class="grandtotals"><?php echo numberToCurrency($totalcostextended)?></td> 
     204                <td align="right" nowrap="nowrap" class="grandtotals">avg. = <?php $numrows?$avgprice=$avgprice/$numrows:$avgprice=0; echo numberToCurrency($avgprice)?></td> 
     205                <td align="right" class="grandtotals"><?php echo numberToCurrency($totalextended)?></td> 
     206            </tr> 
     207         </table> 
     208        <?php 
     209 
     210        $output = ob_get_contents(); 
     211        ob_end_clean(); 
     212 
     213        return $output; 
     214 
     215    }//end function generateSingleHistory 
     216 
     217 
     218 
     219    function generate(){ 
     220 
     221 
     222        ob_start(); 
     223        ?> 
     224 
     225        <h1>Product Sales History</h1> 
     226 
     227        <ul> 
     228            <li> 
     229                source:<br /> 
     230                <?php echo formatVariable($this->dataPrint); ?> 
     231            </li> 
     232            <li> 
     233                date generated:<br /> 
     234                <?php echo dateToString(mktime())." ".timeToString(mktime()); ?> 
     235            </li> 
     236            <li> 
     237                view:<br /> 
     238                <?php echo $this->view; ?> 
     239            </li> 
     240            <li> 
     241                from:<br /> 
     242                <?php echo $this->fromDate; ?> 
     243            </li> 
     244            <li> 
     245                to:<br /> 
     246                <?php echo $this->toDate; ?> 
     247            </li> 
     248        </ul> 
     249 
     250        <?php 
     251 
     252        $this->reportOutput = ob_get_contents(); 
     253        ob_end_clean(); 
     254 
     255        while($therecord = $this->db->fetchArray($this->productQueryresult)){ 
     256 
     257            $this->reportOutput .= '<h2>'.$therecord["partnumber"].'<br />'.$therecord["partname"].'</h2>'; 
     258 
     259            $this->reportOutput .= $this->generateSingleHistory($therecord["uuid"]); 
     260 
     261        }//endwhile 
     262 
     263    }//end function generate 
     264 
     265 
     266    function output(){ 
     267 
     268        global $phpbms; 
     269        $db = &$this->db; 
     270 
     271        $phpbms->cssIncludes[] = "reports.css"; 
     272        $phpbms->cssIncludes[] = "pages/bms/clienthistoryreport.css"; 
     273 
     274        $phpbms->showMenu = false; 
     275        $phpbms->showFooter = false; 
     276 
     277        include("header.php"); 
     278 
     279        echo $this->reportOutput; 
     280 
     281        include("footer.php"); 
     282 
     283    }//end function output 
     284 
     285 
     286    function displayOptions(){ 
     287 
     288        global $phpbms; 
     289        $db = &$this->db; 
     290 
     291        require("include/fields.php"); 
     292 
     293        $pageTitle = "Product Sales History"; 
     294        $phpbms->cssIncludes[] = "pages/historyreports.css"; 
     295        $phpbms->showMenu = false; 
     296 
     297        //Form Elements 
     298        //============================================================== 
     299        $theform = new phpbmsForm(); 
     300 
     301        $thedate = dateToString( mktime(0,0,0,date("m"),1),"SQL" ); 
     302        $theinput = new inputDatePicker("fromdate", $thedate, "from",true); 
     303        $theform->addField($theinput); 
     304 
     305        $thedate = dateToString( mktime(0,0,0,date("m")+1,0,date("Y")), "SQL" ); 
     306        $theinput = new inputDatePicker("todate", $thedate, "to",true); 
     307        $theform->addField($theinput); 
     308 
     309        $theform->jsMerge(); 
     310        //============================================================== 
     311        //End Form Elements 
     312 
     313        include("header.php"); 
     314        ?> 
     315        <form action="<?php echo str_replace("&", "&amp;", $_SERVER["REQUEST_URI"]); ?>" method="post" name="totals" onsubmit="return validateForm(this)"> 
     316 
     317            <div class="bodyline" id="reportOptions"> 
     318 
     319                <h1 id="topTitle"><span>Product Sales History Options</span></h1> 
     320 
     321                <fieldset> 
     322                    <legend>time frame</legend> 
     323 
     324                    <p id="fromP"><?php $theform->showField("fromdate");?></p> 
     325 
     326                    <p><?php $theform->showField("todate");?></p> 
     327                </fieldset> 
     328 
     329                <p> 
     330                    <label for="status">include products from...<br /></label> 
     331                    <select id="status" name="status"> 
     332                        <option value="Orders and Invoices" selected="selected">Orders and Invoices</option> 
     333                        <option value="Invoices">Invoices</option> 
     334                        <option value="Orders">Orders</option> 
     335                    </select> 
     336                </p> 
     337 
     338                <div align="right"> 
     339                    <input name="command" type="submit" class="Buttons" id="print" value="print" /> 
     340                    <input name="cancel" type="button" class="Buttons" id="cancel" value="cancel" onclick="window.close();" /> 
     341                </div> 
     342            </div> 
     343        </form> 
     344 
     345        <?php 
     346        include("footer.php"); 
     347 
     348    }//end function displayOptions 
     349 
     350}//end class  salesHistoryReport 
     351 
     352 
     353/** 
     354 * PROCESSING 
     355 * ============================================================================= 
     356 */ 
     357if(!isset($noOutput)){ 
     358 
     359    //IE needs caching to be set to private in order to display PDFS 
     360    session_cache_limiter('private'); 
     361 
     362    require_once("../../../include/session.php"); 
     363 
     364    checkForReportArguments(); 
     365 
     366    $report = new salesHistoryReport($db, $_GET["rid"], $_GET["tid"]); 
     367 
     368    if(!isset($_POST["command"]) && !isset($_GET["status"])) 
     369        $report->displayOptions(); 
     370    else{ 
     371 
     372        if(isset($_GET["status"])){ 
     373 
     374            $_POST["status"] = $_GET["status"]; 
     375            $_POST["fromdate"] = $_GET["fromdate"]; 
     376            $_POST["todate"] = $_GET["todate"]; 
     377 
     378        }//endif 
     379 
     380        //need to set post variables here 
     381 
     382        $report->setupFromPrintScreen(); 
     383        $report->initialize($_POST); 
     384        $report->generate(); 
     385        $report->output(); 
     386 
     387    }//endif 
     388 
     389 
     390}//end if 
     391 
     392/** 
     393 * When adding a new report record, the add/edit needs to know what the class 
     394 * name is so that it can instantiate it, and grab it's default settings. 
     395 */ 
     396if(isset($addingReportRecord)) 
     397    $reportClass ="salesHistoryReport"; 
     398 
     399 
     400 
     401 
     402 
     403 
     404 
     405 
     406 
     407class s_salesHistoryReport{ 
    45408 
    46409        var $whereclause=""; 
     
    187550 
    188551        function showReport(){ 
    189                  
     552 
    190553        ?> 
    191554<head> 
     
    261624        }//end method 
    262625}//end class 
    263  
    264 if(isset($_POST["command"])){ 
    265         $myreport= new salesHistoryReport(); 
    266         $myreport->initialize($_POST,$db); 
    267  
    268         $myreport->showReport(); 
    269 } else { 
    270  
    271                 require("include/fields.php"); 
    272  
    273                 $pageTitle = "Product Sales History"; 
    274                 $phpbms->cssIncludes[] = "pages/historyreports.css"; 
    275                 $phpbms->showMenu = false; 
    276  
    277                 //Form Elements 
    278                 //============================================================== 
    279                 $theform = new phpbmsForm(); 
    280  
    281  
    282                 $thedate = dateToString( mktime(0,0,0,date("m"),1),"SQL" ); 
    283                 $theinput = new inputDatePicker("fromdate", $thedate, "from",true); 
    284                 $theform->addField($theinput); 
    285  
    286                 $thedate = dateToString( mktime(0,0,0,date("m")+1,0,date("Y")), "SQL" ); 
    287                 $theinput = new inputDatePicker("todate", $thedate, "to",true); 
    288                 $theform->addField($theinput); 
    289  
    290                 $theform->jsMerge(); 
    291                 //============================================================== 
    292                 //End Form Elements 
    293  
    294                 include("header.php"); 
    295626?> 
    296 <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="totals" onsubmit="return validateForm(this)"> 
    297 <div class="bodyline" id="reportOptions"> 
    298         <h1 id="topTitle"><span>Product Sales History Options</span></h1> 
    299                 <fieldset> 
    300                         <legend>time frame</legend> 
    301  
    302                         <p id="fromP"><?php $theform->showField("fromdate");?></p> 
    303  
    304                         <p><?php $theform->showField("todate");?></p> 
    305                 </fieldset> 
    306  
    307                 <p> 
    308                         <label for="status">include line items from...<br /></label> 
    309                    <select id="status" name="status"> 
    310                                 <option value="Orders/Invoices" selected="selected">Orders/Invoices</option> 
    311                                 <option value="Invoices">Invoices</option> 
    312                                 <option value="Orders">Orders</option> 
    313                    </select> 
    314                 </p> 
    315  
    316                 <div align="right"> 
    317                         <input name="command" type="submit" class="Buttons" id="print" value="print" /> 
    318                         <input name="cancel" type="button" class="Buttons" id="cancel" value="cancel" onclick="window.close();" /> 
    319                 </div> 
    320 </div> 
    321 </form> 
    322 <?php 
    323 include("footer.php"); 
    324 }?> 
  • trunk/phpbms/modules/bms/report/receipts_pdf.php

    r673 r693  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39  
    40         if(!isset($_SESSION["userinfo"])){ 
    41  
    42                 //set encoding to latin1 (fpdf doesnt like utf8) 
    43                 $sqlEncoding = "latin1"; 
    44                 require_once("../../../include/session.php"); 
    45  
    46         } 
    47  
    48         if(!class_exists("phpbmsReport")) 
    49                 include("report/report_class.php"); 
    50  
    51         class receiptPDF extends phpbmsReport{ 
    52  
    53                 var $title = "Receipt"; 
    54                 var $lineitemBoxHeight = 4.25; 
    55                 /** 
    56                   * $count 
    57                   * @var int The number of invoice records being displayed 
    58                   */ 
    59                 var $count; 
    60  
    61                 function receiptPDF($db, $orientation='P', $unit='mm', $format='Letter'){ 
    62  
    63                         $this->db = $db; 
    64  
    65                         if(!class_exists("phpbmsPDFReport")) 
    66                                 include("report/pdfreport_class.php"); 
    67  
    68                         $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); 
    69  
    70                         $this->initialize(); 
    71  
    72                 }//end method 
    73  
    74  
    75                 function initialize(){ 
    76                         //This function will set column headings, sizes and formatting 
    77  
    78                         $pdf = &$this->pdf; 
    79  
    80                         $topinfo = array(); 
    81                         $topinfo[] = new pdfColumn("ID", "id", 0.75); 
    82                         $topinfo[] = new pdfColumn("Date", "receiptdate", 1, "date"); 
    83                         $topinfo[] = new pdfColumn("Processed By", "processedby", 0); 
    84  
    85                         $size = 0; 
    86                         foreach($topinfo as $column) 
    87                                 $size += $column->size; 
    88  
    89                         $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    90  
    91                         $this->topinfo = $topinfo; 
    92  
    93  
    94                         $lineitems = array(); 
    95                         $lineitems[] = new pdfColumn("Doc Ref", "relatedid", 0.5); 
    96                         $lineitems[] = new pdfColumn("Type", "type", 0.75); 
    97                         $lineitems[] = new pdfColumn("Doc Date", "itemdate", 0.75, "date"); 
    98                         $lineitems[] = new pdfColumn("Due Date", "duedate", 0.75, "date"); 
    99  
    100                         $lineitems[] = new pdfColumn("Doc Amount", "amount", 0, "currency", "R"); 
    101                         $lineitems[] = new pdfColumn("Applied", "applied", 0.75, "currency", "R"); 
    102                         $lineitems[] = new pdfColumn("Discount", "discount", 0.75, "currency", "R"); 
    103                         $lineitems[] = new pdfColumn("Tax Adj", "taxadjustment", 0.75, "currency", "R"); 
    104  
    105                         $size = 0; 
    106                         foreach($lineitems as $column) 
    107                                 $size += $column->size; 
    108  
    109                         $lineitems[4]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
    110  
    111                         $this->lineitems = $lineitems; 
    112  
    113                         $totalsinfo = array(); 
    114                         $totalsinfo[] = new pdfColumn("Distribution Remaining", "remaining", 0, "currency", "R"); 
    115                         $totalsinfo[] = new pdfColumn("Receipt Total", "amount", 0, "currency", "R"); 
    116  
    117                         $this->totalsinfo = $totalsinfo; 
    118  
    119                 }//end method 
    120  
    121  
    122                 function generate($whereclause = NULL, $sortorder = "receipts.id"){ 
    123  
    124                         $pdf = &$this->pdf; 
    125  
    126                         if($whereclause) 
    127                                 $this->whereclause = $whereclause; 
    128                         elseif(!$this->whereclause) 
    129                                 $this->whereclause = "receipts.id = -400"; 
    130  
    131                         if($sortorder) 
    132                                 $this->sortorder = $sortorder; 
    133                         elseif(!$this->sortorder) 
    134                                 $this->sortorder = "receipts.id"; 
    135  
    136                         $paymentFields = ""; 
    137                         if(ENCRYPT_PAYMENT_FIELDS){ 
    138  
    139                                 $paymentFields = " 
    140                                         ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, 
    141                                         ".$this->db->decrypt("`ccverification`")." AS `ccverification`, 
    142                                         ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, 
    143                                         ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, 
    144                                         ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, 
    145                                 "; 
    146  
    147                         }//end if 
    148  
    149                         $querystatement = " 
    150                                 SELECT 
    151                                         receipts.*, 
    152                                         ".$paymentFields." 
    153  
    154                                         clients.firstname, 
    155                                         clients.lastname, 
    156                                         clients.company, 
    157                                         addresses.address1, 
    158                                         addresses.address2, 
    159                                         addresses.city, 
    160                                         addresses.state, 
    161                                         addresses.postalcode, 
    162                                         addresses.country, 
    163                                         clients.homephone, 
    164                                         clients.workphone, 
    165                                         clients.email, 
    166  
    167                                         paymentmethods.name AS paymentname, 
    168                                         paymentmethods.type AS paymenttype, 
    169  
    170                                         users.firstname AS processorfirst, 
    171                                         users.lastname AS processorlast 
    172  
    173                                 FROM 
    174                                         receipts INNER JOIN clients ON receipts.clientid = clients.uuid 
    175                                         INNER JOIN users ON receipts.modifiedby = users.id INNER JOIN 
    176                                         addresstorecord ON addresstorecord.tabledefid = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary = 1 
    177                                         AND addresstorecord.recordid = clients.uuid INNER JOIN addresses 
    178                                         ON addresstorecord.addressid = addresses.uuid 
    179                                         LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid"; 
    180  
    181                         $querystatement = $this->assembleSQL($querystatement); 
    182                         $queryresult = $this->db->query($querystatement); 
    183  
    184                          
    185                         $this->count = $this->db->numRows($queryresult); 
    186                         if($this->count == 0){ 
    187  
    188                                 $this->_showNoRecords(); 
    189                                 exit; 
    190  
    191                         }//end if 
    192  
    193                         $pdf->hasComapnyHeader = true; 
    194                         $pdf->SetMargins(); 
    195  
    196                         //iterate through each invoice record 
    197                         while($receiptrecord = $this->db->fetchArray($queryresult)){ 
    198  
    199                                 $querystatement = " 
    200                                         SELECT 
    201                                                 SUM(applied) AS thesum 
    202                                         FROM 
    203                                                 receiptitems 
    204                                         WHERE 
    205                                                 receiptid ='".$receiptrecord["uuid"]."' 
    206                                 "; 
    207  
    208                                 $sumresult = $this->db->query($querystatement); 
    209                                 $sumrecord = $this->db->fetchArray($sumresult); 
    210  
    211                                 $receiptrecord["remaining"] = $receiptrecord["amount"] - $sumrecord["thesum"]; 
    212  
    213                                 $this->page = 0; 
    214  
    215                                 $this->receiptrecord = $receiptrecord; 
    216  
    217                                 //adds top info 
    218                                 $top = $this->_addPage(); 
    219  
    220                                 $this->_addLineItems($top); 
    221  
    222                                 $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); 
    223  
    224                                 //totals 
    225                                 $this->_addTotals(); 
    226  
    227                                 //Print any special/instructions and stuff 
    228                                 $this->_addNotes(); 
    229  
    230                         }//end while; 
    231  
    232  
    233                 }//end method 
    234  
    235  
    236                 function _addPage(){ 
    237  
    238                         $pdf = &$this->pdf; 
    239  
    240                         $pdf->AddPage(); 
    241                         $this->page++; 
    242  
    243                         $nextY = $pdf->getY(); 
    244  
    245                         //TITLE 
    246                         $titleWidth=2.375; 
    247                         $titleHeight=.25; 
    248                         $pdf->setStyle("title"); 
    249                         $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); 
    250                         $pdf->Cell($titleWidth, $titleHeight,$this->title, $pdf->borderDebug,1,"R"); 
    251  
    252                         //CLIENT 
    253                         $startY = $pdf->GetY() + 0.75; 
    254  
    255                         $boxHeight = 1.75; 
    256                         $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; 
    257  
    258                         $pdf->setLineWidth(0.02); 
    259                         $pdf->Rect($pdf->leftmargin, $startY, $boxWidth, $boxHeight); 
    260                         $pdf->setLineWidth(0.01); 
    261  
    262                         $pdf->setStyle("header"); 
    263                         $pdf->setY($startY); 
    264                         $pdf->Cell($boxWidth, 0.17, "CLIENT", $pdf->borderDebug, 2, "L", 1); 
    265                         $pdf->setStyle("normal"); 
    266  
    267                         //Company Name 
    268                         $companyDisplay = ""; 
    269                         if($this->receiptrecord["company"]){ 
    270                                 $companyDisplay .= $this->receiptrecord["company"]; 
    271                                 if($this->receiptrecord["firstname"]) 
    272                                         $companyDisplay .= " (".$this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"].")"; 
    273                         } else 
    274                                 $companyDisplay .= $this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"]; 
    275  
    276                         $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
    277                         $pdf->SetFont("Arial", "B", 10); 
    278                         $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); 
    279  
    280                         $client = $this->_setClientInfo(); 
    281  
    282                         $pdf->SetFont("Arial", "", 10); 
    283                         $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
    284                         $pdf->MultiCell($boxWidth - 0.125,.17,$client, $pdf->borderDebug); 
    285  
    286                         //PAYMENT 
    287                         $pdf->setLineWidth(0.02); 
    288                         $pdf->Rect($pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); 
    289                         $pdf->setLineWidth(0.01); 
    290  
    291                         $pdf->setStyle("header"); 
    292                         $pdf->setXY($pdf->leftmargin + $boxWidth + 0.125, $startY); 
    293                         $pdf->Cell($boxWidth, 0.17, "PAYMENT", $pdf->borderDebug, 2, "L", 1); 
    294                         $pdf->setStyle("normal"); 
    295  
    296                         if(!$this->receiptrecord["paymentname"]) 
    297                                 $this->receiptrecord["paymentname"] = "Other"; 
    298  
    299                         $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
    300                         $pdf->SetFont("Arial", "B", 10); 
    301                         $pdf->Cell($boxWidth - 0.125, 0.17, $this->receiptrecord["paymentname"], $pdf->borderDebug, 2, "L"); 
    302  
    303  
    304                         $paymentInfo = $this->_getPaymentInfo(); 
    305                         $pdf->SetFont("Arial", "", 10); 
    306                         $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
    307                         $pdf->MultiCell($boxWidth - 0.125,.17, $paymentInfo, $pdf->borderDebug); 
    308  
    309                         $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); 
    310  
    311                         $this->_addTopInfo(); 
    312  
    313                         //line item headings 
    314                         $pdf->setStyle("header"); 
    315                         $pdf->SetLineWidth(0.02); 
    316  
    317                         $coords["x"] = $pdf->GetX(); 
    318                         $coords["y"] = $pdf->GetY(); 
    319  
    320                         foreach($this->lineitems as $column) 
    321                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    322  
    323  
    324                         return $coords; 
    325  
    326                 }//end method 
    327  
    328  
    329                 function _setClientInfo(){ 
    330  
    331                         $client = $this->receiptrecord["address1"]; 
    332  
    333                         if($this->receiptrecord["address2"]) 
    334                                 $client .= "\n".$this->receiptrecord["address2"]; 
    335  
    336                         $client .="\n".$this->receiptrecord["city"].", ".$this->receiptrecord["state"]." ".$this->receiptrecord["postalcode"]; 
    337  
    338                         if($this->receiptrecord["country"]) 
    339                                 $client .=" ".$this->receiptrecord["country"]; 
    340  
    341                         $phoneemail = ""; 
    342                         if($this->receiptrecord["workphone"] || $this->receiptrecord["homephone"]){ 
    343  
    344                                 if($this->receiptrecord["workphone"]) 
    345                                         $phoneemail = $this->receiptrecord["workphone"]." (W)"; 
    346                                 else 
    347                                         $phoneemail = $this->receiptrecord["homephone"]." (H)"; 
    348  
    349                                 $phoneemail.="\n"; 
    350  
    351                         }//end if 
    352  
    353                         if($this->receiptrecord["email"]) 
    354                                 $phoneemail .= $this->receiptrecord["email"]; 
    355  
    356                         if($phoneemail) 
    357                                 $client .= "\n\n".$phoneemail; 
    358  
    359                         return $client; 
    360  
    361                 }//end method 
    362  
    363  
    364                 function _getPaymentInfo(){ 
    365  
    366                         $info = ""; 
    367  
    368                         switch($this->receiptrecord["paymenttype"]){ 
    369  
    370                                 case "charge": 
    371  
    372                                         $info .= $this->receiptrecord["ccnumber"]; 
    373                                         $info .= "\n Expires: ".$this->receiptrecord["ccexpiration"]; 
    374                                         if($this->receiptrecord["ccverification"]) 
    375                                                 $info .= "\n Verification/Pin: ".$this->receiptrecord["ccverification"]; 
    376                                         break; 
    377  
    378                                 case "draft": 
    379  
    380                                         $info .= $this->receiptrecord["bankname"]; 
    381                                         $info .= "\n Check No: ".$this->receiptrecord["checkno"]; 
    382  
    383                                         if($this->receiptrecord["accountnumber"] || $this->receiptrecord["routingnumber"]) 
    384                                                 $info .= "\n"; 
    385  
    386                                         if($this->receiptrecord["accountnumber"]) 
    387                                                 $info .="\n".$this->receiptrecord["accountnumber"]; 
    388  
    389                                         if($this->receiptrecord["routingnumber"]) 
    390                                                 $info .="\n".$this->receiptrecord["routingnumber"]; 
    391  
    392                                         break; 
    393  
    394                                 default: 
    395  
    396                                         if(!$this->receiptrecord["paymentmethodid"]) 
    397                                                 $info .= $this->receiptrecord["paymentother"]; 
    398  
    399                         }//endswitch 
    400  
    401                         if($this->receiptrecord["transactionid"]) 
    402                                 $info .= "\nTransaction ID: ".$this->receiptrecord["transactionid"]; 
    403  
    404                         return $info; 
    405  
    406                 }//end method 
    407  
    408  
    409                 function _addTopInfo(){ 
    410  
    411                         $pdf = &$this->pdf; 
    412  
    413                         $pdf->setStyle("header"); 
    414                         $pdf->SetLineWidth(0.02); 
    415  
    416                         foreach($this->topinfo as $column) 
    417                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    418  
    419                         $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); 
    420  
    421                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); 
    422  
    423  
    424                         $this->receiptrecord["processedby"] = $this->receiptrecord["processorfirst"]." ".$this->receiptrecord["processorlast"]; 
    425                         $pdf->setStyle("normal"); 
    426  
    427                         foreach($this->topinfo as $column){ 
    428  
    429                                 if($column->format != "") 
    430                                         $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); 
    431                                 else 
    432                                         $value = $this->receiptrecord[$column->fieldname]; 
    433  
    434                                 $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    435  
    436                         }//end foreach 
    437  
    438                         $pdf->SetY($pdf->GetY() + 0.18 + 0.125); 
    439  
    440                 }//end method 
    441  
    442  
    443                 function _addLineItems($coords){ 
    444  
    445                         $pdf = &$this->pdf; 
    446  
    447                         $lineitemresult = $this->_getLineItems(); 
    448  
    449                         $pdf->setStyle("normal"); 
    450  
    451                         $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
    452  
    453                         while($line = $this->db->fetchArray($lineitemresult)){ 
    454  
    455                                 if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ 
    456  
    457                                         $pdf->SetLineWidth(0.02); 
    458                                         $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
    459                                         $pdf->SetLineWidth(0.01); 
    460  
    461                                         $this->_addPage(); 
    462  
    463                                 }//end if 
    464  
    465                                 if($line["type"] == "invoice"){ 
    466  
    467                                         $tempDate = stringToDate($line["itemdate"], "SQL"); 
    468                                         $line["duedate"] = dateToString( strtotime(TERM1_DAYS." days", $tempDate), "SQL" ); 
    469  
    470                                 } else 
    471                                         $line["duedate"] = ""; 
    472  
    473                                 if($line["type"] == "deposit" && $line["relatedid"] == $this->receiptrecord["id"]){ 
    474                                         $line["relatedid"] = ""; 
    475                                         $line["amount"] = 0; 
    476                                         $line["aritemid"] = 0; 
    477                                 } 
    478  
    479                                 if($this->receiptrecord["posted"]) 
    480                                         $line["docdue"] = $line["amount"] - $line["paid"]; 
    481                                 elseif($line["relatedid"]) 
    482                                         $line["docdue"] = $line["amount"] - $line["paid"] - $line["applied"] - $line["discount"] - $line["taxadjustment"]; 
    483                                 else 
    484                                         $line["docDue"] = 0; 
    485  
    486  
    487                                 foreach($this->lineitems as $column){ 
    488  
    489                                         $ln = 0; 
    490  
    491  
    492                                         switch($column->fieldname){ 
    493  
    494                                                 case "parts": 
    495                                                         $pdf->SetFont("Arial", "B", 8); 
    496                                                         $pdf->Write(0.17, $line["partname"]); 
    497                                                         $pdf->setStyle("normal"); 
    498                                                         $pdf->SetX($pdf->leftmargin + $column->size); 
    499                                                         break; 
    500  
    501                                                 default: 
    502                                                         if($column->format != "") 
    503                                                                 $value = formatVariable($line[$column->fieldname], $column->format); 
    504                                                         else 
    505                                                                 $value = $line[$column->fieldname]; 
    506  
    507                                                         if($value == "&middot;") 
    508                                                                 $value = " "; 
    509  
    510                                                         if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) 
    511                                                                 $ln = 2; 
    512  
    513                                                         $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); 
    514                                                         break; 
    515  
    516                                         }//end switch 
    517  
    518                                 }//end foreach 
    519  
    520                                 $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
    521                                 $pdf->SetLineWidth(0.01); 
    522                                 $pdf->SetDrawColor(180,180,180); 
    523                                 $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); 
    524                                 $pdf->SetDrawColor(0,0,0); 
    525                                 $pdf->SetLineWidth(0.02); 
    526                                 $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
    527  
    528                         }//end while 
    529  
    530                         $pdf->SetLineWidth(0.02); 
    531                         $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
    532  
    533                 }//end method 
    534  
    535  
    536                 function _getLineItems(){ 
    537  
    538                         $querystatement = " 
    539                                 SELECT 
    540                                         receiptitems.aritemid, 
    541                                         receiptitems.applied, 
    542                                         receiptitems.discount, 
    543                                         receiptitems.taxadjustment, 
    544                                         aritems.type, 
    545                                         IF(`invoices`.`id`,`invoices`.`id`,`receipts`.`id`) AS `relatedid`, 
    546                                         aritems.itemdate, 
    547                                         aritems.amount, 
    548                                         aritems.paid 
    549                                 FROM 
    550                                         ((receiptitems INNER JOIN aritems ON receiptitems.aritemid = aritems.uuid)LEFT JOIN `invoices` ON `aritems`.`relatedid` = `invoices`.`uuid`) LEFT JOIN `receipts` ON `aritems`.`relatedid` = `receipts`.`uuid` 
    551                                 WHERE 
    552                                         receiptitems.receiptid = '".mysql_real_escape_string($this->receiptrecord["uuid"])."' 
    553                                 ORDER BY 
    554                                         aritems.type, 
    555                                         aritems.itemdate"; 
    556  
    557                                 return $this->db->query($querystatement); 
    558  
    559                 }//end method 
    560  
    561  
    562                 function _addNotes(){ 
    563  
    564                         $pdf = &$this->pdf; 
    565  
    566                         $height = 1; 
    567                         $nextPos = $pdf->GetY() + $height + 0.125; 
    568  
    569                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    570                         $pdf->setStyle("header"); 
    571                         $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes", 1, 2, "L", 1); 
    572  
    573                         $pdf->setStyle("normal"); 
    574                         $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
    575                         $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->receiptrecord["memo"]); 
    576  
    577                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    578  
    579                 }//end method 
    580  
    581  
    582                 function _addTotals(){ 
    583  
    584                         $pdf = &$this->pdf; 
    585  
    586                         $size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin; 
    587  
    588                         $tempTotalsinfo = $this->totalsinfo; 
    589  
    590                         if($this->receiptrecord["remaining"]){ 
    591  
    592                                 $this->totalsinfo[1]->size = 1; 
    593                                 $size -= 1; 
    594  
    595                         } else 
    596                                 array_shift($this->totalsinfo); 
    597  
    598                         $this->totalsinfo[0]->size = $size; 
    599  
    600                         $height = .5; 
    601                         $nextPos = $pdf->GetY() + $height + 0.125; 
    602  
    603                         $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
    604  
    605                         $pdf->setStyle("header"); 
    606  
    607                         foreach($this->totalsinfo as $column) 
    608                                 $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
    609  
    610                         $pdf->setStyle("normal"); 
    611                         $pdf->SetFont("Arial", "B", 10); 
    612                         $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
    613  
    614                         foreach($this->totalsinfo as $column){ 
    615  
    616                                 if($column->format != "") 
    617                                         $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); 
    618                                 else 
    619                                         $value = $this->receiptrecord[$column->fieldname]; 
    620  
    621                                 $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
    622  
    623                         }//end foreach 
    624  
    625                         if(isset($this->totalsinfo[1])) 
    626                                 $this->totalsinfo[1]->size = 0; 
    627  
    628                         $pdf->SetXY($pdf->leftmargin, $nextPos); 
    629  
    630                         $this->totalsinfo = $tempTotalsinfo; 
    631  
    632                 }//end method 
    633  
    634  
    635  
    636                 function output($destination = "screen" , $userinfo = NULL){ 
    637  
    638                         switch($destination){ 
    639  
    640                                 case "screen": 
    641                                         $userinfo = cleanFilename((string)$userinfo); 
    642                                         $this->pdf->Output($userinfo, 'D'); 
    643                                         break; 
    644  
    645                                 case "email": 
    646  
    647                                         if(!$userinfo) 
    648                                                 $userinfo = $_SESSION["userinfo"]; 
    649  
    650                                         if(!$userinfo["email"] || !$this->receiptrecord["email"]) 
    651                                                 return false; 
    652  
    653                                         $pdf = $this->pdf->Output(NULL, "S"); 
    654  
    655                                         $to =           $this->receiptrecord["email"]; 
    656                                         $from =         $userinfo["email"]; 
    657                                         $subject =      "Your ".$this->title." from ".COMPANY_NAME; 
    658                                         $message =      "Attached is your ".$this->title." from ".COMPANY_NAME."\n\n" . 
    659                                                                 "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . 
    660                                                                 "have Acrobat Reader, you can download it at http://www.adobe.com  \n\n" . 
    661                                                                 COMPANY_NAME."\n". 
    662                                                                 COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; 
    663  
    664                                         $headers = "From: $from"; 
    665  
    666                                         $semi_rand = md5( time() ); 
    667                                         $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    668  
    669                                         $headers .= "\nMIME-Version: 1.0\n" . 
    670                                                                 "Content-Type: multipart/mixed;\n" . 
    671                                                                 " boundary=\"{$mime_boundary}\""; 
    672  
    673                                         $message = "This is a multi-part message in MIME format.\n\n" . 
    674                                                         "--{$mime_boundary}\n" . 
    675                                                         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
    676                                                         "Content-Transfer-Encoding: 7bit\n\n" . 
    677                                                         $message . "\n\n"; 
    678  
    679                                         $pdf = chunk_split( base64_encode( $pdf ) ); 
    680  
    681                                         $message .= "--{$mime_boundary}\n" . 
    682                                                          "Content-Type: {application/pdf};\n" . 
    683                                                          " name=\"".$this->title.$this->receiptrecord["id"]."\"\n" . 
    684                                                          "Content-Disposition: attachment;\n" . 
    685                                                          " filename=\"".$this->title.$this->receiptrecord["id"].".pdf\"\n" . 
    686                                                          "Content-Transfer-Encoding: base64\n\n" . 
    687                                                          $pdf . "\n\n" . 
    688                                                          "--{$mime_boundary}--\n"; 
    689  
    690                                         return @ mail($to, $subject, $message, $headers); 
    691  
    692                                         break; 
    693  
    694                         }//endswitch 
    695  
    696                 }//end method 
    697  
    698         }//end class 
    699  
    700  
    701 //PROCESSING 
    702 //============================================================================= 
     39if(!class_exists("phpbmsReport")) 
     40    include("../../../report/report_class.php"); 
     41 
     42class receiptPDF extends phpbmsReport{ 
     43 
     44    var $lineitemBoxHeight = 4.25; 
     45 
     46    /** 
     47      * $count 
     48      * @var int The number of invoice records being displayed 
     49      */ 
     50    var $count; 
     51 
     52 
     53    function receiptPDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ 
     54 
     55        parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
     56 
     57        if(!class_exists("phpbmsPDFReport")) 
     58            include("report/pdfreport_class.php"); 
     59 
     60        $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); 
     61 
     62        $this->checkForDefaultSettings(); 
     63 
     64        $this->initialize(); 
     65 
     66        $this->pdf->borderDebug = $this->settings["borderDebug"]; 
     67 
     68    }//end method 
     69 
     70 
     71    /** 
     72     * function checkForDefaultSettings 
     73     * 
     74     * Checks to make sure loaded report Settings exist and are correct 
     75     */ 
     76    function checkForDefaultSettings(){ 
     77 
     78        if(!isset($this->settings["reportTitle"])) 
     79            $this->settings["reportTitle"] = "Receipt"; 
     80 
     81        if(!isset($this->settings["borderDebug"])) 
     82            $this->settings["borderDebug"] = 0; 
     83 
     84    }//end function checkForDefaultSettings 
     85 
     86 
     87    /** 
     88     * function initialize 
     89     * 
     90     * This function sets column headings sizes, and formatting 
     91     */ 
     92    function initialize(){ 
     93 
     94        $pdf = &$this->pdf; 
     95 
     96        $topinfo = array(); 
     97        $topinfo[] = new pdfColumn("ID", "id", 0.75); 
     98        $topinfo[] = new pdfColumn("Date", "receiptdate", 1, "date"); 
     99        $topinfo[] = new pdfColumn("Processed By", "processedby", 0); 
     100 
     101        $size = 0; 
     102        foreach($topinfo as $column) 
     103                $size += $column->size; 
     104 
     105        $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     106 
     107        $this->topinfo = $topinfo; 
     108 
     109 
     110        $lineitems = array(); 
     111        $lineitems[] = new pdfColumn("Doc Ref", "relatedid", 0.5); 
     112        $lineitems[] = new pdfColumn("Type", "type", 0.75); 
     113        $lineitems[] = new pdfColumn("Doc Date", "itemdate", 0.75, "date"); 
     114        $lineitems[] = new pdfColumn("Due Date", "duedate", 0.75, "date"); 
     115 
     116        $lineitems[] = new pdfColumn("Doc Amount", "amount", 0, "currency", "R"); 
     117        $lineitems[] = new pdfColumn("Applied", "applied", 0.75, "currency", "R"); 
     118        $lineitems[] = new pdfColumn("Discount", "discount", 0.75, "currency", "R"); 
     119        $lineitems[] = new pdfColumn("Tax Adj", "taxadjustment", 0.75, "currency", "R"); 
     120 
     121        $size = 0; 
     122        foreach($lineitems as $column) 
     123                $size += $column->size; 
     124 
     125        $lineitems[4]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; 
     126 
     127        $this->lineitems = $lineitems; 
     128 
     129        $totalsinfo = array(); 
     130        $totalsinfo[] = new pdfColumn("Distribution Remaining", "remaining", 0, "currency", "R"); 
     131        $totalsinfo[] = new pdfColumn("Receipt Total", "amount", 0, "currency", "R"); 
     132 
     133        $this->totalsinfo = $totalsinfo; 
     134 
     135    }//end method 
     136 
     137 
     138        function generate($whereclause = NULL, $sortorder = "receipts.id"){ 
     139 
     140                $pdf = &$this->pdf; 
     141 
     142                if($whereclause) 
     143                        $this->whereClause= $whereclause; 
     144                elseif(!$this->whereClause) 
     145                        $this->whereClause = "receipts.id = -400"; 
     146 
     147                if($sortorder) 
     148                        $this->sortOrder = $sortorder; 
     149                elseif(!$this->sortOrder) 
     150                        $this->sortOrder = "receipts.id"; 
     151 
     152                $paymentFields = ""; 
     153                if(ENCRYPT_PAYMENT_FIELDS){ 
     154 
     155                        $paymentFields = " 
     156                                ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, 
     157                                ".$this->db->decrypt("`ccverification`")." AS `ccverification`, 
     158                                ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, 
     159                                ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, 
     160                                ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, 
     161                        "; 
     162 
     163                }//end if 
     164 
     165                $querystatement = " 
     166                        SELECT 
     167                                receipts.*, 
     168                                ".$paymentFields." 
     169 
     170                                clients.firstname, 
     171                                clients.lastname, 
     172                                clients.company, 
     173                                addresses.address1, 
     174                                addresses.address2, 
     175                                addresses.city, 
     176                                addresses.state, 
     177                                addresses.postalcode, 
     178                                addresses.country, 
     179                                clients.homephone, 
     180                                clients.workphone, 
     181                                clients.email, 
     182 
     183                                paymentmethods.name AS paymentname, 
     184                                paymentmethods.type AS paymenttype, 
     185 
     186                                users.firstname AS processorfirst, 
     187                                users.lastname AS processorlast 
     188 
     189                        FROM 
     190                                receipts INNER JOIN clients ON receipts.clientid = clients.uuid 
     191                                INNER JOIN users ON receipts.modifiedby = users.id INNER JOIN 
     192                                addresstorecord ON addresstorecord.tabledefid = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary = 1 
     193                                AND addresstorecord.recordid = clients.uuid INNER JOIN addresses 
     194                                ON addresstorecord.addressid = addresses.uuid 
     195                                LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid"; 
     196 
     197                $querystatement = $this->assembleSQL($querystatement); 
     198                $queryresult = $this->db->query($querystatement); 
     199 
     200 
     201                $this->count = $this->db->numRows($queryresult); 
     202                if($this->count == 0){ 
     203 
     204                        $this->showNoRecords(); 
     205                        exit; 
     206 
     207                }//end if 
     208 
     209                $pdf->logoInHeader = true; 
     210                $pdf->companyInfoInHeader = true; 
     211                $pdf->SetMargins(); 
     212 
     213                //iterate through each invoice record 
     214                while($receiptrecord = $this->db->fetchArray($queryresult)){ 
     215 
     216                        $querystatement = " 
     217                                SELECT 
     218                                        SUM(applied) AS thesum 
     219                                FROM 
     220                                        receiptitems 
     221                                WHERE 
     222                                        receiptid ='".$receiptrecord["uuid"]."' 
     223                        "; 
     224 
     225                        $sumresult = $this->db->query($querystatement); 
     226                        $sumrecord = $this->db->fetchArray($sumresult); 
     227 
     228                        $receiptrecord["remaining"] = $receiptrecord["amount"] - $sumrecord["thesum"]; 
     229 
     230                        $this->page = 0; 
     231 
     232                        $this->receiptrecord = $receiptrecord; 
     233 
     234                        //adds top info 
     235                        $top = $this->_addPage(); 
     236 
     237                        $this->_addLineItems($top); 
     238 
     239                        $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); 
     240 
     241                        //totals 
     242                        $this->_addTotals(); 
     243 
     244                        //Print any special/instructions and stuff 
     245                        $this->_addNotes(); 
     246 
     247                        $this->receiptrecord = $receiptrecord; 
     248 
     249                }//end while; 
     250 
     251 
     252        }//end method 
     253 
     254 
     255        function _addPage(){ 
     256 
     257                $pdf = &$this->pdf; 
     258 
     259                $pdf->AddPage(); 
     260                $this->page++; 
     261 
     262                $nextY = $pdf->getY(); 
     263 
     264                //TITLE 
     265                $titleWidth=2.375; 
     266                $titleHeight=.25; 
     267                $pdf->setStyle("title"); 
     268                $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); 
     269                $pdf->Cell($titleWidth, $titleHeight, $this->settings["reportTitle"], $pdf->borderDebug,1,"R"); 
     270 
     271                //CLIENT 
     272                $startY = $pdf->GetY() + 0.75; 
     273 
     274                $boxHeight = 1.75; 
     275                $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; 
     276 
     277                $pdf->setLineWidth(0.02); 
     278                $pdf->Rect($pdf->leftmargin, $startY, $boxWidth, $boxHeight); 
     279                $pdf->setLineWidth(0.01); 
     280 
     281                $pdf->setStyle("header"); 
     282                $pdf->setY($startY); 
     283                $pdf->Cell($boxWidth, 0.17, "CLIENT", $pdf->borderDebug, 2, "L", 1); 
     284                $pdf->setStyle("normal"); 
     285 
     286                //Company Name 
     287                $companyDisplay = ""; 
     288                if($this->receiptrecord["company"]){ 
     289                        $companyDisplay .= $this->receiptrecord["company"]; 
     290                        if($this->receiptrecord["firstname"]) 
     291                                $companyDisplay .= " (".$this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"].")"; 
     292                } else 
     293                        $companyDisplay .= $this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"]; 
     294 
     295                $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     296                $pdf->SetFont("Arial", "B", 10); 
     297                $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); 
     298 
     299                $client = $this->_setClientInfo(); 
     300 
     301                $pdf->SetFont("Arial", "", 10); 
     302                $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     303                $pdf->MultiCell($boxWidth - 0.125,.17,$client, $pdf->borderDebug); 
     304 
     305                //PAYMENT 
     306                $pdf->setLineWidth(0.02); 
     307                $pdf->Rect($pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); 
     308                $pdf->setLineWidth(0.01); 
     309 
     310                $pdf->setStyle("header"); 
     311                $pdf->setXY($pdf->leftmargin + $boxWidth + 0.125, $startY); 
     312                $pdf->Cell($boxWidth, 0.17, "PAYMENT", $pdf->borderDebug, 2, "L", 1); 
     313                $pdf->setStyle("normal"); 
     314 
     315                if(!$this->receiptrecord["paymentname"]) 
     316                        $this->receiptrecord["paymentname"] = "Other"; 
     317 
     318                $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); 
     319                $pdf->SetFont("Arial", "B", 10); 
     320                $pdf->Cell($boxWidth - 0.125, 0.17, $this->receiptrecord["paymentname"], $pdf->borderDebug, 2, "L"); 
     321 
     322 
     323                $paymentInfo = $this->_getPaymentInfo(); 
     324                $pdf->SetFont("Arial", "", 10); 
     325                $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); 
     326                $pdf->MultiCell($boxWidth - 0.125,.17, $paymentInfo, $pdf->borderDebug); 
     327 
     328                $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); 
     329 
     330                $this->_addTopInfo(); 
     331 
     332                //line item headings 
     333                $pdf->setStyle("header"); 
     334                $pdf->SetLineWidth(0.02); 
     335 
     336                $coords["x"] = $pdf->GetX(); 
     337                $coords["y"] = $pdf->GetY(); 
     338 
     339                foreach($this->lineitems as $column) 
     340                        $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     341 
     342 
     343                return $coords; 
     344 
     345        }//end method 
     346 
     347 
     348        function _setClientInfo(){ 
     349 
     350                $client = $this->receiptrecord["address1"]; 
     351 
     352                if($this->receiptrecord["address2"]) 
     353                        $client .= "\n".$this->receiptrecord["address2"]; 
     354 
     355                $client .="\n".$this->receiptrecord["city"].", ".$this->receiptrecord["state"]." ".$this->receiptrecord["postalcode"]; 
     356 
     357                if($this->receiptrecord["country"]) 
     358                        $client .=" ".$this->receiptrecord["country"]; 
     359 
     360                $phoneemail = ""; 
     361                if($this->receiptrecord["workphone"] || $this->receiptrecord["homephone"]){ 
     362 
     363                        if($this->receiptrecord["workphone"]) 
     364                                $phoneemail = $this->receiptrecord["workphone"]." (W)"; 
     365                        else 
     366                                $phoneemail = $this->receiptrecord["homephone"]." (H)"; 
     367 
     368                        $phoneemail.="\n"; 
     369 
     370                }//end if 
     371 
     372                if($this->receiptrecord["email"]) 
     373                        $phoneemail .= $this->receiptrecord["email"]; 
     374 
     375                if($phoneemail) 
     376                        $client .= "\n\n".$phoneemail; 
     377 
     378                return $client; 
     379 
     380        }//end method 
     381 
     382 
     383        function _getPaymentInfo(){ 
     384 
     385                $info = ""; 
     386 
     387                switch($this->receiptrecord["paymenttype"]){ 
     388 
     389                        case "charge": 
     390 
     391                                $info .= $this->receiptrecord["ccnumber"]; 
     392                                $info .= "\n Expires: ".$this->receiptrecord["ccexpiration"]; 
     393                                if($this->receiptrecord["ccverification"]) 
     394                                        $info .= "\n Verification/Pin: ".$this->receiptrecord["ccverification"]; 
     395                                break; 
     396 
     397                        case "draft": 
     398 
     399                                $info .= $this->receiptrecord["bankname"]; 
     400                                $info .= "\n Check No: ".$this->receiptrecord["checkno"]; 
     401 
     402                                if($this->receiptrecord["accountnumber"] || $this->receiptrecord["routingnumber"]) 
     403                                        $info .= "\n"; 
     404 
     405                                if($this->receiptrecord["accountnumber"]) 
     406                                        $info .="\n".$this->receiptrecord["accountnumber"]; 
     407 
     408                                if($this->receiptrecord["routingnumber"]) 
     409                                        $info .="\n".$this->receiptrecord["routingnumber"]; 
     410 
     411                                break; 
     412 
     413                        default: 
     414 
     415                                if(!$this->receiptrecord["paymentmethodid"]) 
     416                                        $info .= $this->receiptrecord["paymentother"]; 
     417 
     418                }//endswitch 
     419 
     420                if($this->receiptrecord["transactionid"]) 
     421                        $info .= "\nTransaction ID: ".$this->receiptrecord["transactionid"]; 
     422 
     423                return $info; 
     424 
     425        }//end method 
     426 
     427 
     428        function _addTopInfo(){ 
     429 
     430                $pdf = &$this->pdf; 
     431 
     432                $pdf->setStyle("header"); 
     433                $pdf->SetLineWidth(0.02); 
     434 
     435                foreach($this->topinfo as $column) 
     436                        $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     437 
     438                $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); 
     439 
     440                $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); 
     441 
     442 
     443                $this->receiptrecord["processedby"] = $this->receiptrecord["processorfirst"]." ".$this->receiptrecord["processorlast"]; 
     444                $pdf->setStyle("normal"); 
     445 
     446                foreach($this->topinfo as $column){ 
     447 
     448                        if($column->format != "") 
     449                                $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); 
     450                        else 
     451                                $value = $this->receiptrecord[$column->fieldname]; 
     452 
     453                        $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     454 
     455                }//end foreach 
     456 
     457                $pdf->SetY($pdf->GetY() + 0.18 + 0.125); 
     458 
     459        }//end method 
     460 
     461 
     462        function _addLineItems($coords){ 
     463 
     464                $pdf = &$this->pdf; 
     465 
     466                $lineitemresult = $this->_getLineItems(); 
     467 
     468                $pdf->setStyle("normal"); 
     469 
     470                $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); 
     471 
     472                while($line = $this->db->fetchArray($lineitemresult)){ 
     473 
     474                        if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ 
     475 
     476                                $pdf->SetLineWidth(0.02); 
     477                                $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
     478                                $pdf->SetLineWidth(0.01); 
     479 
     480                                $this->_addPage(); 
     481 
     482                        }//end if 
     483 
     484                        if($line["type"] == "invoice"){ 
     485 
     486                                $tempDate = stringToDate($line["itemdate"], "SQL"); 
     487                                $line["duedate"] = dateToString( strtotime(TERM1_DAYS." days", $tempDate), "SQL" ); 
     488 
     489                        } else 
     490                                $line["duedate"] = ""; 
     491 
     492                        if($line["type"] == "deposit" && $line["relatedid"] == $this->receiptrecord["id"]){ 
     493                                $line["relatedid"] = ""; 
     494                                $line["amount"] = 0; 
     495                                $line["aritemid"] = 0; 
     496                        } 
     497 
     498                        if($this->receiptrecord["posted"]) 
     499                                $line["docdue"] = $line["amount"] - $line["paid"]; 
     500                        elseif($line["relatedid"]) 
     501                                $line["docdue"] = $line["amount"] - $line["paid"] - $line["applied"] - $line["discount"] - $line["taxadjustment"]; 
     502                        else 
     503                                $line["docDue"] = 0; 
     504 
     505 
     506                        foreach($this->lineitems as $column){ 
     507 
     508                                $ln = 0; 
     509 
     510 
     511                                switch($column->fieldname){ 
     512 
     513                                        case "parts": 
     514                                                $pdf->SetFont("Arial", "B", 8); 
     515                                                $pdf->Write(0.17, $line["partname"]); 
     516                                                $pdf->setStyle("normal"); 
     517                                                $pdf->SetX($pdf->leftmargin + $column->size); 
     518                                                break; 
     519 
     520                                        default: 
     521                                                if($column->format != "") 
     522                                                        $value = formatVariable($line[$column->fieldname], $column->format); 
     523                                                else 
     524                                                        $value = $line[$column->fieldname]; 
     525 
     526                                                if($value == "&middot;") 
     527                                                        $value = " "; 
     528 
     529                                                if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) 
     530                                                        $ln = 2; 
     531 
     532                                                $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); 
     533                                                break; 
     534 
     535                                }//end switch 
     536 
     537                        }//end foreach 
     538 
     539                        $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
     540                        $pdf->SetLineWidth(0.01); 
     541                        $pdf->SetDrawColor(180,180,180); 
     542                        $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); 
     543                        $pdf->SetDrawColor(0,0,0); 
     544                        $pdf->SetLineWidth(0.02); 
     545                        $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); 
     546 
     547                }//end while 
     548 
     549                $pdf->SetLineWidth(0.02); 
     550                $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); 
     551 
     552        }//end method 
     553 
     554 
     555        function _getLineItems(){ 
     556 
     557                $querystatement = " 
     558                        SELECT 
     559                                receiptitems.aritemid, 
     560                                receiptitems.applied, 
     561                                receiptitems.discount, 
     562                                receiptitems.taxadjustment, 
     563                                aritems.type, 
     564                                IF(`invoices`.`id`,`invoices`.`id`,`receipts`.`id`) AS `relatedid`, 
     565                                aritems.itemdate, 
     566                                aritems.amount, 
     567                                aritems.paid 
     568                        FROM 
     569                                ((receiptitems INNER JOIN aritems ON receiptitems.aritemid = aritems.uuid)LEFT JOIN `invoices` ON `aritems`.`relatedid` = `invoices`.`uuid`) LEFT JOIN `receipts` ON `aritems`.`relatedid` = `receipts`.`uuid` 
     570                        WHERE 
     571                                receiptitems.receiptid = '".mysql_real_escape_string($this->receiptrecord["uuid"])."' 
     572                        ORDER BY 
     573                                aritems.type, 
     574                                aritems.itemdate"; 
     575 
     576                        return $this->db->query($querystatement); 
     577 
     578        }//end method 
     579 
     580 
     581        function _addNotes(){ 
     582 
     583                $pdf = &$this->pdf; 
     584 
     585                $height = 1; 
     586                $nextPos = $pdf->GetY() + $height + 0.125; 
     587 
     588                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     589                $pdf->setStyle("header"); 
     590                $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes", 1, 2, "L", 1); 
     591 
     592                $pdf->setStyle("normal"); 
     593                $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); 
     594                $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->receiptrecord["memo"]); 
     595 
     596                $pdf->SetXY($pdf->leftmargin, $nextPos); 
     597 
     598        }//end method 
     599 
     600 
     601        function _addTotals(){ 
     602 
     603                $pdf = &$this->pdf; 
     604 
     605                $size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin; 
     606 
     607                $tempTotalsinfo = $this->totalsinfo; 
     608 
     609                if($this->receiptrecord["remaining"]){ 
     610 
     611                        $this->totalsinfo[1]->size = 1; 
     612                        $size -= 1; 
     613 
     614                } else 
     615                        array_shift($this->totalsinfo); 
     616 
     617                $this->totalsinfo[0]->size = $size; 
     618 
     619                $height = .5; 
     620                $nextPos = $pdf->GetY() + $height + 0.125; 
     621 
     622                $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); 
     623 
     624                $pdf->setStyle("header"); 
     625 
     626                foreach($this->totalsinfo as $column) 
     627                        $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); 
     628 
     629                $pdf->setStyle("normal"); 
     630                $pdf->SetFont("Arial", "B", 10); 
     631                $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); 
     632 
     633                foreach($this->totalsinfo as $column){ 
     634 
     635                        if($column->format != "") 
     636                                $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); 
     637                        else 
     638                                $value = $this->receiptrecord[$column->fieldname]; 
     639 
     640                        $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); 
     641 
     642                }//end foreach 
     643 
     644                if(isset($this->totalsinfo[1])) 
     645                        $this->totalsinfo[1]->size = 0; 
     646 
     647                $pdf->SetXY($pdf->leftmargin, $nextPos); 
     648 
     649                $this->totalsinfo = $tempTotalsinfo; 
     650 
     651        }//end method 
     652 
     653 
     654 
     655        function output($destination = "screen" , $userinfo = NULL){ 
     656 
     657                switch($destination){ 
     658 
     659                        case "screen": 
     660                                $userinfo = cleanFilename((string)$userinfo); 
     661                                $this->pdf->Output($userinfo, 'D'); 
     662                                break; 
     663 
     664                        case "email": 
     665 
     666                                if(!$userinfo) 
     667                                        $userinfo = $_SESSION["userinfo"]; 
     668 
     669                                if(!$userinfo["email"] || !$this->receiptrecord["email"]) 
     670                                        return false; 
     671 
     672                                $pdf = $this->pdf->Output(NULL, "S"); 
     673 
     674                                $to =           $this->receiptrecord["email"]; 
     675                                $from =         $userinfo["email"]; 
     676                                $subject =      "Your ".$this->settings["reportTitle"]." from ".COMPANY_NAME; 
     677                                $message =      "Attached is your ".$this->settings["reportTitle"]." from ".COMPANY_NAME."\n\n" . 
     678                                                        "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . 
     679                                                        "have Acrobat Reader, you can download it at http://www.adobe.com  \n\n" . 
     680                                                        COMPANY_NAME."\n". 
     681                                                        COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; 
     682 
     683                                $headers = "From: $from"; 
     684 
     685                                $semi_rand = md5( time() ); 
     686                                $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
     687 
     688                                $headers .= "\nMIME-Version: 1.0\n" . 
     689                                                        "Content-Type: multipart/mixed;\n" . 
     690                                                        " boundary=\"{$mime_boundary}\""; 
     691 
     692                                $message = "This is a multi-part message in MIME format.\n\n" . 
     693                                                "--{$mime_boundary}\n" . 
     694                                                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
     695                                                "Content-Transfer-Encoding: 7bit\n\n" . 
     696                                                $message . "\n\n"; 
     697 
     698                                $pdf = chunk_split( base64_encode( $pdf ) ); 
     699 
     700                                $message .= "--{$mime_boundary}\n" . 
     701                                                 "Content-Type: {application/pdf};\n" . 
     702                                                 " name=\"".$this->settings["reportTitle"].$this->receiptrecord["id"]."\"\n" . 
     703                                                 "Content-Disposition: attachment;\n" . 
     704                                                 " filename=\"".$this->settings["reportTitle"].$this->receiptrecord["id"].".pdf\"\n" . 
     705                                                 "Content-Transfer-Encoding: base64\n\n" . 
     706                                                 $pdf . "\n\n" . 
     707                                                 "--{$mime_boundary}--\n"; 
     708 
     709                                return @ mail($to, $subject, $message, $headers); 
     710 
     711                                break; 
     712 
     713                }//endswitch 
     714 
     715        }//end method 
     716 
     717   /** 
     718     * function addingRecordDefaultSettings 
     719     * 
     720     * Creates an array of settings associative arrays for use by the system when 
     721     * a new report record is added that references the file containing this class 
     722     * 
     723     * @retrun array of settings. Each setting should itself be 
     724     * an associative array containing the following 
     725     * name: name of the setting 
     726     * defaultvalue: default value for setting 
     727     * type: (string, int, real, bool) type for value of setting 
     728     * required: (0,1) whether the setting is required or not 
     729     * description: brief description for what this setting is used for. 
     730     */ 
     731    function addingRecordDefaultSettings(){ 
     732 
     733        $settings[] = array( 
     734            "name"=>"reportTitle", 
     735            "defaultValue"=>"Receipt", 
     736            "type"=>"string", 
     737            "required"=>1, 
     738            "description"=>"Title printed in upper right hand of report." 
     739        ); 
     740 
     741        return $settings; 
     742 
     743    }//endfunction addingRecordDefaultSettings 
     744 
     745}//end class 
     746 
     747 
     748/** 
     749 * PROCESSING 
     750 * ============================================================================= 
     751 */ 
    703752if(!isset($noOutput)){ 
    704753 
    705         //IE needs caching to be set to private in order to display PDFS 
    706         session_cache_limiter('private'); 
    707  
    708  
    709  
    710         $report = new receiptPDF($db, 'P', 'in', 'Letter'); 
    711         $report->setupFromPrintScreen(); 
    712         $report->generate(); 
    713          
    714         $filename = 'Receipts_'; 
    715         if($report->count === 1){ 
    716                  
    717                 if($report->invoicerecord["company"]) 
    718                         $filename .= "_".$report->invoicerecord["company"]; 
    719                  
    720                 $filename .= "_".$report->invoicerecord["id"]; 
    721                  
    722         }elseif((int)$report->count) 
    723                 $filename .= "_Multiple"; 
    724          
    725         $filename .= ".pdf"; 
    726         $report->output('screen', $filename); 
     754    //IE needs caching to be set to private in order to display PDFS 
     755    session_cache_limiter('private'); 
     756 
     757    //set encoding to latin1 (fpdf doesnt like utf8) 
     758    $sqlEncoding = "latin1"; 
     759    require_once("../../../include/session.php"); 
     760 
     761    checkForReportArguments(); 
     762 
     763    $report = new receiptPDF($db, $_GET["rid"], $_GET["tid"], 'P', 'in', 'Letter'); 
     764    $report->setupFromPrintScreen(); 
     765    $report->generate(); 
     766 
     767    $filename = 'Receipts'; 
     768 
     769    if($report->count === 1){ 
     770 
     771        if($report->receiptrecord["company"]) 
     772            $filename .= "_".$report->receiptrecord["company"]; 
     773        else 
     774            $filename .= "_".$report->receiptrecord["firstname"]."_".$report->receiptrecord["lastname"]; 
     775 
     776        $filename .= "_".$report->receiptrecord["id"]; 
     777 
     778    }elseif((int)$report->count) 
     779        $filename .= "_MultiClient"; 
     780 
     781    $filename .= ".pdf"; 
     782    $report->output('screen', $filename); 
    727783 
    728784}//end if 
    729785 
     786/** 
     787 * When adding a new report record, the add/edit needs to know what the class 
     788 * name is so that it can instantiate it, and grab it's default settings. 
     789 */ 
     790if(isset($addingReportRecord)) 
     791    $reportClass ="receiptPDF"; 
    730792?> 
  • trunk/phpbms/modules/bms/report/receipts_pttotals.php

    r611 r693  
    3939 
    4040if(!class_exists("phpbmsReport")) 
    41         include("../../../report/report_class.php"); 
     41    include("../../../report/report_class.php"); 
    4242 
    4343class receiptsPTTotals extends phpbmsReport{ 
    4444 
    45         function receiptsPTTotals($db){ 
    46  
    47                 parent::phpbmsReport($db); 
     45        function receiptsPTTotals($db, $reportUUID, $tabledefUUID){ 
     46 
     47            parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 
    4848 
    4949        }//end method 
     
    6767                                LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid)"; 
    6868 
    69                 if($this->sortorder) 
    70                         $this->sortorder = "paymentmethods.id DESC, ".$this->sortorder; 
     69                if($this->sortOrder) 
     70                        $this->sortOrder= "paymentmethods.id DESC, ".$this->sortorder; 
    7171                else 
    72                         $this->sortorder = "paymentmethods.id DESC, receipts.receiptdate"; 
     72                        $this->sortOrder= "paymentmethods.id DESC, receipts.receiptdate"; 
    7373 
    7474                $querystatement = $this->assembleSQL($querystatement); 
     
    216216        }//end method 
    217217 
    218 }//end method 
    219  
    220  
    221         //PROCESSING 
    222         //======================================================================== 
    223  
    224         if(!isset($noOutput)){ 
    225  
    226                 session_cache_limiter('private'); 
    227  
    228                 require("../../../include/session.php"); 
    229  
    230                 $report = new receiptsPTTotals($db); 
    231                 $report->setupFromPrintScreen(); 
    232                 $report->generate(); 
    233                 $report->show(); 
    234  
    235         }//end if 
    236  
     218}//end class 
     219 
     220 
     221/** 
     222 * PROCESSING 
     223 * ============================================================================= 
     224 */ 
     225if(!isset($noOutput)){ 
     226 
     227    session_cache_limiter('private'); 
     228 
     229    require("../../../include/session.php"); 
     230 
     231    checkForReportArguments(); 
     232 
     233    $report = new receiptsPTTotals($db, $_GET["rid"], $_GET["tid"]); 
     234    $report->setupFromPrintScreen(); 
     235    $report->generate(); 
     236    $report->show(); 
     237 
     238}//end if 
     239 
     240/** 
     241 * When adding a new report record, the add/edit needs to know what the class 
     242 * name is so that it can instantiate it, and grab it's default settings. 
     243 */ 
     244if(isset($addingReportRecord)) 
     245    $reportClass ="generalExport"; 
    237246?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.