fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [11827] Merge 11823:11826 from trunk


From: Sigurd Nes
Subject: [Fmsystem-commits] [11827] Merge 11823:11826 from trunk
Date: Fri, 14 Mar 2014 16:21:39 +0000

Revision: 11827
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11827
Author:   sigurdne
Date:     2014-03-14 16:21:38 +0000 (Fri, 14 Mar 2014)
Log Message:
-----------
Merge 11823:11826 from trunk

Modified Paths:
--------------
    branches/Version-1_0-branch/rental/inc/class.sobilling.inc.php
    branches/Version-1_0-branch/rental/inc/class.socommon.inc.php
    branches/Version-1_0-branch/rental/inc/class.uibilling.inc.php
    branches/Version-1_0-branch/rental/inc/model/class.agresso_lg04.inc.php

Property Changed:
----------------
    branches/Version-1_0-branch/


Property changes on: branches/Version-1_0-branch
___________________________________________________________________
Modified: svn:mergeinfo
   - 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851,6853-6869,6871-6874,6876-6877,6879,6881,6883,6885-6886,6888-6893,6895-6897,6899-6901,6903,6905-6907,6909,6911-6929,6931-6936,6938-6947,6949,6951,6953,6955-6956,6958-6959,6961-6968,6970-6971,6973-6974,6976-6978,6980,6982-7017,7019-7025,7027-7035,7037-7039,7041-7045,7047-7055,7057,7059-7065,7067-7069,7071,7073,7075-7076,7078,7080-7081,7083,7085,7087,7089-7097,7099-7102,7104-7105,7107-7111,7113-7120,7122-7124,7126-7129,7131,7133-7141,7143,7145-7146,7148-7150,7152-7153,7155-7158,7160-7164,7166-7167,7169-7170,7172,7174,7176,7178,7180-7181,7183,7185,7187-7188,7190,7192-7196,7198-7199,7201-7203,7205,7207,7209-7210,7212,7214,7216-7217,7219-7222,7224-7226,7228-7229,7231,7233-7234,7236-7238,7240-7241,7243-7244,7246,7248,7250,7252-7256,7258-7259,7261-7264,7266-7273,7275-7279,7281-7332,7334-7338,7340-7348,7350,7352-7353,7355-7361,7363-7366,7368-7370,7372,7374,7376,7378,7380-7386,7388-7400,7402,7404-7433,7435-7439,7441-7446,7448-7458,7460-7469,7471-7483,7485-7487,7489-7490,7492,7494,7496-7497,7499,7501-7502,7504,7506-7507,7509-7511,7513-7517,7519-7521,7523,7525,7527-7529,7531,7533,7535-7538,7540-7542,7544-7549,7551-7552,7554-7561,7563,7565,7567-7573,7575-7578,7580-7584,7586-7591,7593-7624,7627-7636,7638-7656,7658-7718,7720-7732,7734,7736,7738-7750,7754-7759,7761-7767,7769-7780,7782,7784-7809,7811-7812,7814-7835,7837-7847,7849-7887,7889-7895,7897,7899,7901,7903-7905,7907-7921,7923-7925,7927-7933,7935,7937-7952,7954-7968,7970-7974,7976,7978-7979,7981-7982,7984-7988,7990-7992,7994-8041,8043-8066,8068-8087,8089,8091-8108,8110-8124,8126-8129,8131,8133-8150,8152-8154,8156-8162,8164-8167,8169-8170,8172-8179,8181,8183-8196,8198-8207,8209-8211,8213-8214,8216-8217,8219-8220,8222,8224-8225,8227-8247,8249,8251,8253-8282,8284-8352,8354-8368,8370-8396,8398-8430,8432,8434-8440,8442-8445,8447-8453,8455-8456,8458,8460,8462-8464,8466-8473,8475-8479,8481,8483-8501,8503-8523,8525,8527-8531,8533,8535-8536,8538-8550,8552-8554,8556-8557,8559-8579,8581-8587,8589,8591-8592,8594-8595,8597-8601,8603-8610,8612-8613,8615,8617,8619-8645,8647-8650,8652-8661,8663-8666,8668-8669,8671-8683,8685-8691,8693-8730,8732-8737,8739,8741-8767,8769,8771-8772,8774,8776-8797,8799-8812,8814-8819,8821,8823-8833,8835-8837,8839,8841,8843-8849,8852-8858,8860-8867,8869-8870,8872,8874-8877,8879,8881,8883-8888,8890,8892-8901,8903-8911,8913-8917,8920-8923,8925-8933,8935-8938,8940-8943,8945,8947-8948,8950,8952-8953,8955-8962,8964,8966,8968-8970,8972-8975,8977-8983,8985-8993,8995-9001,9003,9005,9007,9009,9011-9019,9021-9023,9025,9027-9028,9030-9044,9046-9047,9049-9050,9052-9056,9058-9059,9061,9063-9064,9066-9068,9071-9092,9094-9112,9114-9117,9119,9121-9160,9162-9166,9169-9207,9209-9211,9213-9215,9217,9219,9221-9253,9255,9257,9259-9260,9262,9264-9269,9271-9273,9275,9277-9278,9280,9282-9283,9285-9289,9291-9299,9301-9310,9312-9313,9315-9320,9322-9324,9326-9338,9340-9342,9344,9346-9348,9350-9358,9360-9362,9364-9366,9368-9374,9376-9382,9384,9386,9388-9390,9392-9396,9398-9402,9404-9410,9412,9414,9416-9417,9419-9425,9427,9429-9430,9432,9434-9463,9465-9502,9504-9506,9508-9521,9523-9526,9528,9530-9537,9539,9541-9551,9553,9555-9556,9558-9578,9580-9581,9583,9585,9587,9589,9591-9624,9626-9655,9657-9700,9702-9726,9728-9729,9731-9749,9751,9753-9754,9756-9832,9834-9836,9838-9839,9841-9846,9848-9850,9852-9858,9860-9863,9865,9867,9869-9871,9873-9893,9895,9897-9912,9914-9919,9921-9928,9930-9952,9954,9956,9958-9963,9965-9993,9995-9997,9999-10001,10003-10004,10006-10007,10009-10012,10014-10031,10033-10073,10075-10107,10109-10165,10167-10210,10222-10226,10228-10311,10313-10378,10380,10382,10384-10393,10395-10478,10480-10482,10484-10494,10496-10503,10505,10507,10509-10521,10523,10525-10528,10530-10540,10542-10543,10545-10568,10570-10584,10586-10590,10592-10594,10596,10598-10599,10601-10611,10613,10615,10617-10626,10628-10636,10638,10640-10654,10656-10658,10660,10662-10672,10674,10676-10682,10684,10686,10688-10690,10692-10694,10696-10697,10699-10701,10703,10705-10706,10708-10724,10726-10731,10734,10736-10748,10750-10796,10798-10939,10941,10943,10945,10947-10953,10955,10957-10961,10963,10965-10966,10968-11001,11003-11030,11032-11034,11036,11038,11040,11042-11053,11055-11059,11061-11062,11064-11068,11070-11073,11075-11077,11079-11083,11085,11087-11088,11090-11093,11095-11108,11110-11111,11113,11115-11116,11118-11120,11122,11124-11129,11131-11132,11134,11136,11138,11140-11151,11153-11161,11163-11185,11187-11189,11191-11229,11231,11233,11235-11264,11266-11267,11269-11278,11280-11282,11284-11291,11293-11295,11297,11299-11302,11304,11306,11309,11311,11313-11316,11318-11323,11325-11332,11334,11336-11344,11346,11348-11354,11356,11358-11360,11363-11386,11388-11389,11391-11392,11394,11396-11403,11405-11406,11408,11410,11412,11415,11417,11419-11420,11422,11424-11429,11431-11442,11444-11445,11447-11460,11462-11464,11466-11470,11472-11475,11477-11478,11480-11487,11489-11492,11494,11496,11498,11500-11502,11504-11506,11508,11510-11511,11513,11515,11517-11523,11525-11526,11528-11531,11533,11535-11538,11540-11546,11548-11560,11563-11572,11574,11576,11578,11580-11581,11583,11585,11587,11589-11592,11594-11595,11597,11599,11601,11603,11605-11607,11609-11611,11613,11615-11619,11621-11622,11624-11630,11632,11634-11635,11637,11639-11640,11642,11644-11655,11657-11659,11661-11675,11677-11679,11681-11684,11686,11688,11690-11691,11693-11706,11708-11709,11711-11714,11716-11718,11720-11728,11730,11732,11734-11739,11741-11757,11759-11760,11762-11766,11768,11770-11771,11773,11775,11777,11779-11780,11782,11784,11786,11788,11790,11792-11793,11795,11797,11799,11801,11803-11804,11806-11807,11809,11811-11814,11816-11820,11822
   + 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851,6853-6869,6871-6874,6876-6877,6879,6881,6883,6885-6886,6888-6893,6895-6897,6899-6901,6903,6905-6907,6909,6911-6929,6931-6936,6938-6947,6949,6951,6953,6955-6956,6958-6959,6961-6968,6970-6971,6973-6974,6976-6978,6980,6982-7017,7019-7025,7027-7035,7037-7039,7041-7045,7047-7055,7057,7059-7065,7067-7069,7071,7073,7075-7076,7078,7080-7081,7083,7085,7087,7089-7097,7099-7102,7104-7105,7107-7111,7113-7120,7122-7124,7126-7129,7131,7133-7141,7143,7145-7146,7148-7150,7152-7153,7155-7158,7160-7164,7166-7167,7169-7170,7172,7174,7176,7178,7180-7181,7183,7185,7187-7188,7190,7192-7196,7198-7199,7201-7203,7205,7207,7209-7210,7212,7214,7216-7217,7219-7222,7224-7226,7228-7229,7231,7233-7234,7236-7238,7240-7241,7243-7244,7246,7248,7250,7252-7256,7258-7259,7261-7264,7266-7273,7275-7279,7281-7332,7334-7338,7340-7348,7350,7352-7353,7355-7361,7363-7366,7368-7370,7372,7374,7376,7378,7380-7386,7388-7400,7402,7404-7433,7435-7439,7441-7446,7448-7458,7460-7469,7471-7483,7485-7487,7489-7490,7492,7494,7496-7497,7499,7501-7502,7504,7506-7507,7509-7511,7513-7517,7519-7521,7523,7525,7527-7529,7531,7533,7535-7538,7540-7542,7544-7549,7551-7552,7554-7561,7563,7565,7567-7573,7575-7578,7580-7584,7586-7591,7593-7624,7627-7636,7638-7656,7658-7718,7720-7732,7734,7736,7738-7750,7754-7759,7761-7767,7769-7780,7782,7784-7809,7811-7812,7814-7835,7837-7847,7849-7887,7889-7895,7897,7899,7901,7903-7905,7907-7921,7923-7925,7927-7933,7935,7937-7952,7954-7968,7970-7974,7976,7978-7979,7981-7982,7984-7988,7990-7992,7994-8041,8043-8066,8068-8087,8089,8091-8108,8110-8124,8126-8129,8131,8133-8150,8152-8154,8156-8162,8164-8167,8169-8170,8172-8179,8181,8183-8196,8198-8207,8209-8211,8213-8214,8216-8217,8219-8220,8222,8224-8225,8227-8247,8249,8251,8253-8282,8284-8352,8354-8368,8370-8396,8398-8430,8432,8434-8440,8442-8445,8447-8453,8455-8456,8458,8460,8462-8464,8466-8473,8475-8479,8481,8483-8501,8503-8523,8525,8527-8531,8533,8535-8536,8538-8550,8552-8554,8556-8557,8559-8579,8581-8587,8589,8591-8592,8594-8595,8597-8601,8603-8610,8612-8613,8615,8617,8619-8645,8647-8650,8652-8661,8663-8666,8668-8669,8671-8683,8685-8691,8693-8730,8732-8737,8739,8741-8767,8769,8771-8772,8774,8776-8797,8799-8812,8814-8819,8821,8823-8833,8835-8837,8839,8841,8843-8849,8852-8858,8860-8867,8869-8870,8872,8874-8877,8879,8881,8883-8888,8890,8892-8901,8903-8911,8913-8917,8920-8923,8925-8933,8935-8938,8940-8943,8945,8947-8948,8950,8952-8953,8955-8962,8964,8966,8968-8970,8972-8975,8977-8983,8985-8993,8995-9001,9003,9005,9007,9009,9011-9019,9021-9023,9025,9027-9028,9030-9044,9046-9047,9049-9050,9052-9056,9058-9059,9061,9063-9064,9066-9068,9071-9092,9094-9112,9114-9117,9119,9121-9160,9162-9166,9169-9207,9209-9211,9213-9215,9217,9219,9221-9253,9255,9257,9259-9260,9262,9264-9269,9271-9273,9275,9277-9278,9280,9282-9283,9285-9289,9291-9299,9301-9310,9312-9313,9315-9320,9322-9324,9326-9338,9340-9342,9344,9346-9348,9350-9358,9360-9362,9364-9366,9368-9374,9376-9382,9384,9386,9388-9390,9392-9396,9398-9402,9404-9410,9412,9414,9416-9417,9419-9425,9427,9429-9430,9432,9434-9463,9465-9502,9504-9506,9508-9521,9523-9526,9528,9530-9537,9539,9541-9551,9553,9555-9556,9558-9578,9580-9581,9583,9585,9587,9589,9591-9624,9626-9655,9657-9700,9702-9726,9728-9729,9731-9749,9751,9753-9754,9756-9832,9834-9836,9838-9839,9841-9846,9848-9850,9852-9858,9860-9863,9865,9867,9869-9871,9873-9893,9895,9897-9912,9914-9919,9921-9928,9930-9952,9954,9956,9958-9963,9965-9993,9995-9997,9999-10001,10003-10004,10006-10007,10009-10012,10014-10031,10033-10073,10075-10107,10109-10165,10167-10210,10222-10226,10228-10311,10313-10378,10380,10382,10384-10393,10395-10478,10480-10482,10484-10494,10496-10503,10505,10507,10509-10521,10523,10525-10528,10530-10540,10542-10543,10545-10568,10570-10584,10586-10590,10592-10594,10596,10598-10599,10601-10611,10613,10615,10617-10626,10628-10636,10638,10640-10654,10656-10658,10660,10662-10672,10674,10676-10682,10684,10686,10688-10690,10692-10694,10696-10697,10699-10701,10703,10705-10706,10708-10724,10726-10731,10734,10736-10748,10750-10796,10798-10939,10941,10943,10945,10947-10953,10955,10957-10961,10963,10965-10966,10968-11001,11003-11030,11032-11034,11036,11038,11040,11042-11053,11055-11059,11061-11062,11064-11068,11070-11073,11075-11077,11079-11083,11085,11087-11088,11090-11093,11095-11108,11110-11111,11113,11115-11116,11118-11120,11122,11124-11129,11131-11132,11134,11136,11138,11140-11151,11153-11161,11163-11185,11187-11189,11191-11229,11231,11233,11235-11264,11266-11267,11269-11278,11280-11282,11284-11291,11293-11295,11297,11299-11302,11304,11306,11309,11311,11313-11316,11318-11323,11325-11332,11334,11336-11344,11346,11348-11354,11356,11358-11360,11363-11386,11388-11389,11391-11392,11394,11396-11403,11405-11406,11408,11410,11412,11415,11417,11419-11420,11422,11424-11429,11431-11442,11444-11445,11447-11460,11462-11464,11466-11470,11472-11475,11477-11478,11480-11487,11489-11492,11494,11496,11498,11500-11502,11504-11506,11508,11510-11511,11513,11515,11517-11523,11525-11526,11528-11531,11533,11535-11538,11540-11546,11548-11560,11563-11572,11574,11576,11578,11580-11581,11583,11585,11587,11589-11592,11594-11595,11597,11599,11601,11603,11605-11607,11609-11611,11613,11615-11619,11621-11622,11624-11630,11632,11634-11635,11637,11639-11640,11642,11644-11655,11657-11659,11661-11675,11677-11679,11681-11684,11686,11688,11690-11691,11693-11706,11708-11709,11711-11714,11716-11718,11720-11728,11730,11732,11734-11739,11741-11757,11759-11760,11762-11766,11768,11770-11771,11773,11775,11777,11779-11780,11782,11784,11786,11788,11790,11792-11793,11795,11797,11799,11801,11803-11804,11806-11807,11809,11811-11814,11816-11820,11822,11824-11826

Modified: branches/Version-1_0-branch/rental/inc/class.sobilling.inc.php
===================================================================
--- branches/Version-1_0-branch/rental/inc/class.sobilling.inc.php      
2014-03-14 16:13:01 UTC (rev 11826)
+++ branches/Version-1_0-branch/rental/inc/class.sobilling.inc.php      
2014-03-14 16:21:38 UTC (rev 11827)
@@ -1,423 +1,433 @@
 <?php
-phpgw::import_class('rental.socommon');
-phpgw::import_class('rental.sobilling_info');
-include_class('rental', 'agresso_gl07', 'inc/model/');
-include_class('rental', 'agresso_lg04', 'inc/model/');
-include_class('rental', 'agresso_cs15', 'inc/model/');
-include_class('rental', 'billing_info', 'inc/model/');
-include_class('rental', 'party', 'inc/model/');
+       phpgw::import_class('rental.socommon');
+       phpgw::import_class('rental.sobilling_info');
+       include_class('rental', 'agresso_gl07', 'inc/model/');
+       include_class('rental', 'agresso_lg04', 'inc/model/');
+       include_class('rental', 'agresso_cs15', 'inc/model/');
+       include_class('rental', 'billing_info', 'inc/model/');
+       include_class('rental', 'party', 'inc/model/');
 
-class rental_sobilling extends rental_socommon
-{
-       protected static $so;
-       protected $billing_terms; // Used for caching the billing terms
-       public $vfs;
-       
-       /**
-        * Get a static reference to the storage object associated with this 
model object
-        * 
-        * @return the storage object
-        */
-       public static function get_instance()
+       class rental_sobilling extends rental_socommon
        {
-               if (self::$so == null) {
-                       self::$so = CreateObject('rental.sobilling');
-                       $virtual_file_system = CreateObject('phpgwapi.vfs');
-                       $virtual_file_system->override_acl = 1;
-                       self::$so->vfs = $virtual_file_system;
-               }
-               return self::$so;
-       }
 
-       protected function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count)
-       {
-               $clauses = array('1=1');
-               if($sort_field == 'description')
+               protected static $so;
+               protected $billing_terms; // Used for caching the billing terms
+               public $vfs;
+
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                * 
+                * @return the storage object
+                */
+               public static function get_instance()
                {
-                       $sort_field = "title";
+                       if(self::$so == null)
+                       {
+                               self::$so = CreateObject('rental.sobilling');
+                               $virtual_file_system                            
 = CreateObject('phpgwapi.vfs');
+                               $virtual_file_system->override_acl       = 1;
+                               self::$so->vfs                                  
         = $virtual_file_system;
+                       }
+                       return self::$so;
                }
-               if(isset($filters[$this->get_id_field_name()]))
+
+               protected function get_query(string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count)
                {
-                       $filter_clauses[] = 
"rb.{$this->marshal($this->get_id_field_name(),'field')} = 
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
+                       $clauses = array('1=1');
+                       if($sort_field == 'description')
+                       {
+                               $sort_field = "title";
+                       }
+                       if(isset($filters[$this->get_id_field_name()]))
+                       {
+                               $filter_clauses[] = 
"rb.{$this->marshal($this->get_id_field_name(), 'field')} = 
{$this->marshal($filters[$this->get_id_field_name()], 'int')}";
+                       }
+                       if(isset($filters['location_id']))
+                       {
+                               $location_id             = 
$this->marshal($filters['location_id'], 'int');
+                               $filter_clauses[]        = 
"rb.location_id=$location_id";
+                               $filter_clauses[]        = "rb.timestamp_commit 
is null";
+                       }
+                       $filter_clauses[] = "rb.deleted = false";
+                       if(count($filter_clauses))
+                       {
+                               $clauses[] = join(' AND ', $filter_clauses);
+                       }
+                       $condition = join(' AND ', $clauses);
+
+                       $tables  = "rental_billing rb";
+                       $joins   = $this->left_join . ' rental_billing_info rbi 
ON (rb.id = rbi.billing_id)';
+                       $joins .= $this->left_join . ' 
rental_contract_responsibility rcr ON (rcr.location_id = rb.location_id)';
+                       if($return_count) // We should only return a count
+                       {
+                               $cols = 'COUNT(DISTINCT(rb.id)) AS count';
+                       }
+                       else
+                       {
+                               $cols    = 'rb.id, rb.total_sum, rb.success, 
rb.created_by, rb.timestamp_start, rb.timestamp_stop, rb.timestamp_commit, 
rb.location_id, rb.title, rb.export_format, rbi.id as billing_info_id, 
rbi.term_id, rbi.month, rbi.year, rcr.title as responsibility_title';
+                               $dir     = $ascending ? 'ASC' : 'DESC';
+                               $order   = $sort_field ? "ORDER BY 
rb.{$this->marshal($sort_field, 'field')} {$dir}" : 'ORDER BY rb.timestamp_stop 
DESC';
+                       }
+                       //var_dump("SELECT {$cols} FROM {$tables} {$joins} 
WHERE {$condition} {$order}");
+                       return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
                }
-               if(isset($filters['location_id']))
+
+               protected function populate(int $billing_id, &$billing)
                {
-                       $location_id = $this->marshal($filters['location_id'], 
'int');
-                       $filter_clauses[] = "rb.location_id=$location_id";
-                       $filter_clauses[] = "rb.timestamp_commit is null";
-               }
-               $filter_clauses[] = "rb.deleted = false";
-               if(count($filter_clauses))
-               {
-                       $clauses[] = join(' AND ', $filter_clauses);
-               }
-               $condition =  join(' AND ', $clauses);
+                       if($billing == null)
+                       {
+                               $billing = new 
rental_billing($this->db->f('id', true), $this->db->f('location_id', true), 
$this->db->f('title', true), $this->db->f('created_by', true));
+                               $billing->set_success($this->db->f('success', 
true));
+                               
$billing->set_total_sum($this->db->f('total_sum', true));
+                               
$billing->set_timestamp_start($this->db->f('timestamp_start', true));
+                               
$billing->set_timestamp_stop($this->db->f('timestamp_stop', true));
+                               
$billing->set_timestamp_commit($this->db->f('timestamp_commit', true));
+                               
$billing->set_export_format($this->db->f('export_format', true));
+                               
$billing->set_responsibility_title(lang($this->unmarshal($this->db->f('responsibility_title'),
 'string')));
 
-               $tables = "rental_billing rb";
-               $joins = $this->left_join.' rental_billing_info rbi ON (rb.id = 
rbi.billing_id)';
-               $joins .= $this->left_join.' rental_contract_responsibility rcr 
ON (rcr.location_id = rb.location_id)';
-               if($return_count) // We should only return a count
-               {
-                       $cols = 'COUNT(DISTINCT(rb.id)) AS count';
-               }
-               else
-               {
-                       $cols = 'rb.id, rb.total_sum, rb.success, 
rb.created_by, rb.timestamp_start, rb.timestamp_stop, rb.timestamp_commit, 
rb.location_id, rb.title, rb.export_format, rbi.id as billing_info_id, 
rbi.term_id, rbi.month, rbi.year, rcr.title as responsibility_title';
-                       $dir = $ascending ? 'ASC' : 'DESC';
-                       $order = $sort_field ? "ORDER BY 
rb.{$this->marshal($sort_field, 'field')} {$dir}": 'ORDER BY rb.timestamp_stop 
DESC';
-               }
-               //var_dump("SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}");
-               return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
-       }
-       
-       protected function populate(int $billing_id, &$billing)
-       {
-               if($billing == null)
-               {
-                       $billing = new rental_billing($this->db->f('id', true), 
$this->db->f('location_id', true), $this->db->f('title', true), 
$this->db->f('created_by', true));
-                       $billing->set_success($this->db->f('success', true));
-                       $billing->set_total_sum($this->db->f('total_sum', 
true));
-                       
$billing->set_timestamp_start($this->db->f('timestamp_start', true));
-                       
$billing->set_timestamp_stop($this->db->f('timestamp_stop', true));
-                       
$billing->set_timestamp_commit($this->db->f('timestamp_commit', true));
-                       
$billing->set_export_format($this->db->f('export_format', true));
-                       
$billing->set_responsibility_title(lang($this->unmarshal($this->db->f('responsibility_title'),
 'string')));
-                       
-                       $id = $this->db->f('id', true);
-                       
-                       $export_exist = $this->vfs->file_exists
-                       (
+                               $id = $this->db->f('id', true);
+
+                               $export_exist = $this->vfs->file_exists
+                               (
                                array
-                               (
+                                       (
                                        'string' => "/rental/billings/{$id}",
                                        RELATIVE_NONE
                                )
-                       );
-               
-                       if($export_exist)
-                       {
-                               $billing->set_generated_export(true);
+                               );
+
+                               if($export_exist)
+                               {
+                                       $billing->set_generated_export(true);
+                               }
+
+                               /* if($this->db->f('export_data', true) != null)
+                                 {
+                                 $billing->set_generated_export(true);
+                                 } */
                        }
-                       
-                       /*if($this->db->f('export_data', true) != null)
+
+                       $billing_info_id = 
$this->unmarshal($this->db->f('billing_info_id', true), 'int');
+                       if($billing_info_id)
                        {
-                               $billing->set_generated_export(true);
-                       }*/
-               }
-               
-               $billing_info_id = 
$this->unmarshal($this->db->f('billing_info_id', true), 'int');
-               if($billing_info_id)
-               {
-                       $billing_info = new 
rental_billing_info($billing_info_id);
-                       
$billing_info->set_term_id($this->unmarshal($this->db->f('term_id', true), 
'int'));
-                       
$billing_info->set_month($this->unmarshal($this->db->f('month', true), 'int'));
-                       
$billing_info->set_year($this->unmarshal($this->db->f('year', true), 'int'));
-                       if($billing_info->get_term_id() == 2){ // yearly
-                               $billing_info->set_term_label(lang('annually'));
-                       }
-                       else if($billing_info->get_term_id() == 3){ // half year
-                               if($billing_info->get_month() == 6){
-                                       
$billing_info->set_term_label(lang('first_half'));
+                               $billing_info = new 
rental_billing_info($billing_info_id);
+                               
$billing_info->set_term_id($this->unmarshal($this->db->f('term_id', true), 
'int'));
+                               
$billing_info->set_month($this->unmarshal($this->db->f('month', true), 'int'));
+                               
$billing_info->set_year($this->unmarshal($this->db->f('year', true), 'int'));
+                               if($billing_info->get_term_id() == 2)
+                               { // yearly
+                                       
$billing_info->set_term_label(lang('annually'));
                                }
-                               else{
-                                       
$billing_info->set_term_label(lang('second_half'));
+                               else if($billing_info->get_term_id() == 3)
+                               { // half year
+                                       if($billing_info->get_month() == 6)
+                                       {
+                                               
$billing_info->set_term_label(lang('first_half'));
+                                       }
+                                       else
+                                       {
+                                               
$billing_info->set_term_label(lang('second_half'));
+                                       }
                                }
-                               
-                       }
-                       else if($billing_info->get_term_id() == 4){ // quarterly
-                               if($billing_info->get_month() == 3){
-                                       
$billing_info->set_term_label(lang('first_quarter'));
+                               else if($billing_info->get_term_id() == 4)
+                               { // quarterly
+                                       if($billing_info->get_month() == 3)
+                                       {
+                                               
$billing_info->set_term_label(lang('first_quarter'));
+                                       }
+                                       else if($billing_info->get_month() == 6)
+                                       {
+                                               
$billing_info->set_term_label(lang('second_quarter'));
+                                       }
+                                       else if($billing_info->get_month() == 9)
+                                       {
+                                               
$billing_info->set_term_label(lang('third_quarter'));
+                                       }
+                                       else
+                                       {
+                                               
$billing_info->set_term_label(lang('fourth_quarter'));
+                                       }
                                }
-                               else if($billing_info->get_month() == 6){
-                                       
$billing_info->set_term_label(lang('second_quarter'));
-                               }
-                               else if($billing_info->get_month() == 9){
-                                       
$billing_info->set_term_label(lang('third_quarter'));
-                               }
-                               else{
-                                       
$billing_info->set_term_label(lang('fourth_quarter'));
-                               }
+                               $billing->add_billing_info($billing_info);
                        }
-                       $billing->add_billing_info($billing_info);
+                       return $billing;
                }
-               return $billing;
-       }
-       
-       protected function get_id_field_name()
-       {
-               return 'id';
-       }
-       
-       public function add(&$billing)
-       {
-               $values = array
-               (
-                       $this->marshal($billing->get_total_sum(), 'float'),
-                       $billing->is_success() ? 'true' : 'false',
-                       $this->marshal($billing->get_created_by(), 'int'),
-                       $this->marshal($billing->get_timestamp_start(), 'int'),
-                       $this->marshal($billing->get_timestamp_stop(), 'int'),
-                       $this->marshal($billing->get_timestamp_commit(), 'int'),
-                       $this->marshal($billing->get_location_id(), 'int'),
-                       $this->marshal($billing->get_title(), 'string'),
-                       $billing->is_deleted() ? 'true' : 'false',
-                       $this->marshal($billing->get_export_format(), 'string'),
-               );
-               $query ="INSERT INTO rental_billing(total_sum, success, 
created_by, timestamp_start, timestamp_stop, timestamp_commit, location_id, 
title, deleted, export_format) VALUES (" . join(',', $values) . ")";
-               $receipt = null;
-               if($this->db->query($query))
+
+               protected function get_id_field_name()
                {
-                       $receipt = array();
-                       $receipt['id'] = 
$this->db->get_last_insert_id('rental_billing', 'id');
-                       $billing->set_id($receipt['id']);
+                       return 'id';
                }
-               return $receipt;
-       }
-       
-       public function update($billing)
-       {
-               $values = array(
-                       'total_sum = ' . 
$this->marshal($billing->get_total_sum(), 'float'),
-                       "success = '" . ($billing->is_success() ? 'true' : 
'false') . "'",
-                       'timestamp_start = ' . 
$this->marshal($billing->get_timestamp_start(), 'int'),
-                       'timestamp_stop = ' . 
$this->marshal($billing->get_timestamp_stop(), 'int'),
-                       'timestamp_commit = ' . 
$this->marshal($billing->get_timestamp_commit(), 'int'),
-                       'location_id = ' . 
$this->marshal($billing->get_location_id(), 'int'),
-                       'title = ' . $this->marshal($billing->get_title(), 
'string'),
-                       "deleted = '" . ($billing->is_deleted() ? 'true' : 
'false') . "'",
-                       'export_format = ' . 
$this->marshal($billing->get_export_format(), 'string'),
-               );
-               $result = $this->db->query("UPDATE rental_billing SET " . 
join(',', $values) . " WHERE id={$billing->get_id()}", __LINE__,__FILE__);
-       }
-       
-       /**
-        * Get a key/value array of titles of billing term types keyed by their 
id
-        * 
-        * @return array
-        */
-       function get_billing_terms()
-       {
-               if($this->billing_terms == null)
+
+               public function add(&$billing)
                {
-                       $sql = "SELECT id, title FROM rental_billing_term ORDER 
BY months DESC";
-                       //FIXME Sigurd 21.june 2010: this query trigger 
fetch_single mode for next_record()
-                       $this->db->query($sql, __LINE__, __FILE__,false,true);
-                       $results = array();
-                       while($this->db->next_record())
+                       $values  = array
+                       (
+                               $this->marshal($billing->get_total_sum(), 
'float'),
+                               $billing->is_success() ? 'true' : 'false',
+                               $this->marshal($billing->get_created_by(), 
'int'),
+                               $this->marshal($billing->get_timestamp_start(), 
'int'),
+                               $this->marshal($billing->get_timestamp_stop(), 
'int'),
+                               
$this->marshal($billing->get_timestamp_commit(), 'int'),
+                               $this->marshal($billing->get_location_id(), 
'int'),
+                               $this->marshal($billing->get_title(), 'string'),
+                               $billing->is_deleted() ? 'true' : 'false',
+                               $this->marshal($billing->get_export_format(), 
'string'),
+                       );
+                       $query   = "INSERT INTO rental_billing(total_sum, 
success, created_by, timestamp_start, timestamp_stop, timestamp_commit, 
location_id, title, deleted, export_format) VALUES (" . join(',', $values) . 
")";
+                       $receipt = null;
+                       if($this->db->query($query))
                        {
-                               $results[$this->db->f('id')] = 
$this->db->f('title', true);
+                               $receipt                 = array();
+                               $receipt['id']   = 
$this->db->get_last_insert_id('rental_billing', 'id');
+                               $billing->set_id($receipt['id']);
                        }
-                       $this->billing_terms = $results;
+                       return $receipt;
                }
-               
-               return $this->billing_terms;
-       }
-       
-       public function get_missing_billing_info(int $billing_term, int $year, 
int $mont, array $contracts_to_bill, array $contracts_overriding_billing_start, 
string $export_format)
-       {
-               $exportable = null;
-               $missing_billing_info = array();
-               switch($export_format)
+
+               public function update($billing)
                {
-                       case 'agresso_gl07':
-                               $exportable = $export_format;
-                               break;
-                       case 'agresso_lg04':
-                               $exportable = $export_format;
-                               break;
-                       default:
-                               $missing_billing_info[] = 'Unknown export 
format.';
-                               break;
+                       $values  = array
+                       (
+                               'total_sum = ' . 
$this->marshal($billing->get_total_sum(), 'float'),
+                               "success = '" . ($billing->is_success() ? 
'true' : 'false') . "'",
+                               'timestamp_start = ' . 
$this->marshal($billing->get_timestamp_start(), 'int'),
+                               'timestamp_stop = ' . 
$this->marshal($billing->get_timestamp_stop(), 'int'),
+                               'timestamp_commit = ' . 
$this->marshal($billing->get_timestamp_commit(), 'int'),
+                               'location_id = ' . 
$this->marshal($billing->get_location_id(), 'int'),
+                               'title = ' . 
$this->marshal($billing->get_title(), 'string'),
+                               "deleted = '" . ($billing->is_deleted() ? 
'true' : 'false') . "'",
+                               'export_format = ' . 
$this->marshal($billing->get_export_format(), 'string'),
+                       );
+                       $result  = $this->db->query("UPDATE rental_billing SET 
" . join(',', $values) . " WHERE id={$billing->get_id()}", __LINE__, __FILE__);
                }
-               foreach($contracts_to_bill as $contract_id) // Runs through all 
the contracts that should be billed in this run
+
+               /**
+                * Get a key/value array of titles of billing term types keyed 
by their id
+                * 
+                * @return array
+                */
+               function get_billing_terms()
                {
-                       $contract = 
rental_socontract::get_instance()->get_single($contract_id);
-                       $info = null;
+                       if($this->billing_terms == null)
+                       {
+                               $sql     = "SELECT id, title FROM 
rental_billing_term ORDER BY months DESC";
+                               //FIXME Sigurd 21.june 2010: this query trigger 
fetch_single mode for next_record()
+                               $this->db->query($sql, __LINE__, __FILE__, 
false, true);
+                               $results = array();
+                               while($this->db->next_record())
+                               {
+                                       $results[$this->db->f('id')] = 
$this->db->f('title', true);
+                               }
+                               $this->billing_terms = $results;
+                       }
+
+                       return $this->billing_terms;
+               }
+
+               public function get_missing_billing_info(int $billing_term, int 
$year, int $mont, array $contracts_to_bill, array 
$contracts_overriding_billing_start, string $export_format)
+               {
+                       $exportable                              = null;
+                       $missing_billing_info    = array();
                        switch($export_format)
                        {
                                case 'agresso_gl07':
-                                       $info = 
rental_agresso_gl07::get_missing_billing_info($contract);
+                                       $exportable                             
 = $export_format;
                                        break;
                                case 'agresso_lg04':
-                                       $info = 
rental_agresso_lg04::get_missing_billing_info($contract);
+                                       $exportable                             
 = $export_format;
                                        break;
+                               default:
+                                       $missing_billing_info[]  = 'Unknown 
export format.';
+                                       break;
                        }
-                       if($info != null && count($info) > 0)
+                       foreach($contracts_to_bill as $contract_id) // Runs 
through all the contracts that should be billed in this run
                        {
-                               $missing_billing_info[$contract_id] = $info;
+                               $contract        = 
rental_socontract::get_instance()->get_single($contract_id);
+                               $info            = null;
+                               switch($export_format)
+                               {
+                                       case 'agresso_gl07':
+                                               $info    = 
rental_agresso_gl07::get_missing_billing_info($contract);
+                                               break;
+                                       case 'agresso_lg04':
+                                               $info    = 
rental_agresso_lg04::get_missing_billing_info($contract);
+                                               break;
+                               }
+                               if($info != null && count($info) > 0)
+                               {
+                                       $missing_billing_info[$contract_id] = 
$info;
+                               }
                        }
+                       return $missing_billing_info;
                }
-               return $missing_billing_info;
-       }
-               
-       public function create_billing(int $decimals, int $contract_type, int 
$billing_term, int $year, int $month, $title, int $created_by, array 
$contracts_to_bill, array $contracts_overriding_billing_start, string 
$export_format, int $existing_billing, array $contracts_bill_only_one_time)
-       {
-               if($contracts_overriding_billing_start == null){
-                       $contracts_overriding_billing_start = array();
-               }
-               
-               if($contracts_bill_only_one_time == null){
-                       $contracts_bill_only_one_time = array();
-               }
-               
-               // We start a transaction before running the billing
-               $this->db->transaction_begin();
-               if($existing_billing < 1){ //new billing
-                       $billing = new rental_billing(-1, $contract_type, 
$title, $created_by); // The billing job itself
-                       $billing->set_timestamp_start(time()); // Start of run
-                       $billing->set_export_format($export_format);
-                       $billing->set_title($title);
-                       $this->store($billing); // Store job as it is
-                       $billing_end_timestamp = strtotime('-1 day', 
strtotime(($month == 12 ? ($year + 1) : $year) . '-' . ($month == 12 ? '01' : 
($month + 1)) . '-01')); // Last day of billing period is the last day of the 
month we're billing
-                       $counter = 0;
-                       $total_sum = 0;
-               }
-               else{
-                       $billing = $this->get_single($existing_billing);
-                       $billing_end_timestamp = strtotime('-1 day', 
strtotime(($month == 12 ? ($year + 1) : $year) . '-' . ($month == 12 ? '01' : 
($month + 1)) . '-01')); // Last day of billing period is the last day of the 
month we're billing
-                       $total_sum = $billing->get_total_sum();
-               }
 
-               $billing_info = new rental_billing_info(null, 
$billing->get_id(), $contract_type, $billing_term, $year, $month);
-               $res = 
rental_sobilling_info::get_instance()->store($billing_info);
-               
-               // Get the number of months in selected term for contract
-               $months = 
rental_socontract::get_instance()->get_months_in_term($billing_term);
-               
-               // The billing should start from the first date of the periode 
(term) we're billing for
-               $first_day_of_selected_month = strtotime($year . '-' . $month . 
'-01');
-               $bill_from_timestamp = strtotime('-'.($months-1).' month', 
$first_day_of_selected_month); 
-               
-               foreach($contracts_to_bill as $contract_id) // Runs through all 
the contracts that should be billed in this run
+               public function create_billing(int $decimals, int 
$contract_type, int $billing_term, int $year, int $month, $title, int 
$created_by, array $contracts_to_bill, array 
$contracts_overriding_billing_start, string $export_format, int 
$existing_billing, array $contracts_bill_only_one_time)
                {
-                       $invoice = rental_invoice::create_invoice($decimals, 
$billing->get_id(), $contract_id, 
in_array($contract_id,$contracts_overriding_billing_start) ? true : 
false,$bill_from_timestamp, 
$billing_end_timestamp,in_array($contract_id,$contracts_bill_only_one_time) ? 
true : false ); // Creates an invoice of the contract
-                       if($invoice != null)
+                       if($contracts_overriding_billing_start == null)
                        {
-                               $total_sum += $invoice->get_total_sum();
+                               $contracts_overriding_billing_start = array();
                        }
+
+                       if($contracts_bill_only_one_time == null)
+                       {
+                               $contracts_bill_only_one_time = array();
+                       }
+
+                       // We start a transaction before running the billing
+                       $this->db->transaction_begin();
+                       if($existing_billing < 1)
+                       { //new billing
+                               $billing                                 = new 
rental_billing(-1, $contract_type, $title, $created_by); // The billing job 
itself
+                               $billing->set_timestamp_start(time()); // Start 
of run
+                               $billing->set_export_format($export_format);
+                               $billing->set_title($title);
+                               $this->store($billing); // Store job as it is
+                               $billing_end_timestamp   = strtotime('-1 day', 
strtotime(($month == 12 ? ($year + 1) : $year) . '-' . ($month == 12 ? '01' : 
($month + 1)) . '-01')); // Last day of billing period is the last day of the 
month we're billing
+                               $counter                                 = 0;
+                               $total_sum                               = 0;
+                       }
+                       else
+                       {
+                               $billing                                 = 
$this->get_single($existing_billing);
+                               $billing_end_timestamp   = strtotime('-1 day', 
strtotime(($month == 12 ? ($year + 1) : $year) . '-' . ($month == 12 ? '01' : 
($month + 1)) . '-01')); // Last day of billing period is the last day of the 
month we're billing
+                               $total_sum                               = 
$billing->get_total_sum();
+                       }
+
+                       $billing_info    = new rental_billing_info(null, 
$billing->get_id(), $contract_type, $billing_term, $year, $month);
+                       $res                     = 
rental_sobilling_info::get_instance()->store($billing_info);
+
+                       // Get the number of months in selected term for 
contract
+                       $months = 
rental_socontract::get_instance()->get_months_in_term($billing_term);
+
+                       // The billing should start from the first date of the 
periode (term) we're billing for
+                       $first_day_of_selected_month = strtotime($year . '-' . 
$month . '-01');
+                       $bill_from_timestamp             = strtotime('-' . 
($months - 1) . ' month', $first_day_of_selected_month);
+
+                       foreach($contracts_to_bill as $contract_id) // Runs 
through all the contracts that should be billed in this run
+                       {
+                               $invoice = 
rental_invoice::create_invoice($decimals, $billing->get_id(), $contract_id, 
in_array($contract_id, $contracts_overriding_billing_start) ? true : false, 
$bill_from_timestamp, $billing_end_timestamp, in_array($contract_id, 
$contracts_bill_only_one_time) ? true : false ); // Creates an invoice of the 
contract
+                               if($invoice != null)
+                               {
+                                       $total_sum += $invoice->get_total_sum();
+                               }
+                       }
+                       $billing->set_total_sum(round($total_sum, $decimals));
+                       $billing->set_timestamp_stop(time()); //  End of run
+                       $billing->set_success(true); // Billing job is a success
+                       $this->store($billing); // Store job now that we're done
+                       // End of transaction!
+                       if($this->db->transaction_commit())
+                       {
+                               return $billing;
+                       }
+                       throw new UnexpectedValueException('Transaction 
failed.');
                }
-               $billing->set_total_sum(round($total_sum, $decimals));
-               $billing->set_timestamp_stop(time()); //  End of run
-               $billing->set_success(true); // Billing job is a success
-               $this->store($billing); // Store job now that we're done
-               // End of transaction!
-               if ($this->db->transaction_commit()) { 
-                       return $billing;
-               }
-               throw new UnexpectedValueException('Transaction failed.');
-       }
-       
-       /**
-        * Helper method to check if a period has been billed before.
-        * 
-        * @param $contract_type
-        * @param $billing_term
-        * @param $year
-        * @param $month
-        * @return boolean true if the period has been billed before, false if 
not.
-        */
-       public function has_been_billed($contract_type, $billing_term, $year, 
$month)
-       {
-               $sql = "SELECT COUNT(id) AS count FROM rental_billing_info 
WHERE location_id = {$this->marshal($contract_type,'int')} AND term_id = 
{$this->marshal($billing_term,'int')} AND year = {$this->marshal($year,'int')} 
AND month = {$this->marshal($month,'int')} AND deleted = false";
-               $result = $this->db->query($sql, __LINE__, __FILE__);
-               if($result && $this->db->next_record())
+
+               /**
+                * Helper method to check if a period has been billed before.
+                * 
+                * @param $contract_type
+                * @param $billing_term
+                * @param $year
+                * @param $month
+                * @return boolean true if the period has been billed before, 
false if not.
+                */
+               public function has_been_billed($contract_type, $billing_term, 
$year, $month)
                {
-                       return ($this->unmarshal($this->db->f('count', true), 
'int') > 0);
+                       $sql     = "SELECT COUNT(id) AS count FROM 
rental_billing_info WHERE location_id = {$this->marshal($contract_type, 'int')} 
AND term_id = {$this->marshal($billing_term, 'int')} AND year = 
{$this->marshal($year, 'int')} AND month = {$this->marshal($month, 'int')} AND 
deleted = false";
+                       $result  = $this->db->query($sql, __LINE__, __FILE__);
+                       if($result && $this->db->next_record())
+                       {
+                               return ($this->unmarshal($this->db->f('count', 
true), 'int') > 0);
+                       }
+                       return false;
                }
-               return false;
-       }
-       
-       /**
-        * Generates export data and stores in database.
-        * 
-        * @param $billing_job
-        */
-       public function generate_export(&$billing_job, $excel_export=false)
-       {
-      set_time_limit(1000);
-               $exportable = null;
-               switch($billing_job->get_export_format())
+
+               /**
+                * Generates export data and stores in database.
+                * 
+                * @param $billing_job
+                */
+               public function generate_export(&$billing_job, $excel_export = 
false)
                {
-                       case 'agresso_gl07':
-                               $exportable = new 
rental_agresso_gl07($billing_job);
-                               break;
-                       case 'agresso_lg04':
-                               $exportable = new 
rental_agresso_lg04($billing_job);
-                               break;
-                       /*default:
-                               $exportable = new 
rental_default_export($billing_job);
-                               break;*/
-               }
-               if($exportable != null)
-               {
-                    if($excel_export)
-                    {
-                        $export_data = $exportable->get_contents_excel();
-                        //_debug_array($export_data[1]);
-                        return $export_data;
-                    }
-                    else
-                    {
-                       //$sql = "UPDATE rental_billing SET export_data = 
{$this->marshal(iconv("ISO-8859-1","UTF-8",$exportable->get_contents()),'string')}
 WHERE id = {$this->marshal($billing_job->get_id(),'int')}";
-                       //$result = $this->db->query($sql, __LINE__, __FILE__);
-
-                       $vfs = CreateObject('phpgwapi.vfs');
-                       $vfs->override_acl = 1;
-                       
-                       $path = "/rental";
-                       $dir = array('string' => $path, RELATIVE_NONE);
-                       if(!$vfs->file_exists($dir)){
-                               if(!$vfs->mkdir($dir))
-                               {
-                                       return;
-                               }
+                       $exportable = null;
+                       switch($billing_job->get_export_format())
+                       {
+                               case 'agresso_gl07':
+                                       $exportable      = new 
rental_agresso_gl07($billing_job);
+                                       break;
+                               case 'agresso_lg04':
+                                       $exportable      = new 
rental_agresso_lg04($billing_job);
+                                       break;
+                               /* default:
+                                 $exportable = new 
rental_default_export($billing_job);
+                                 break; */
                        }
-                       
-                       $path .= "/billings";
-                       $dir = array('string' => $path, RELATIVE_NONE);
-                       if(!$vfs->file_exists($dir)){
-                               if(!$vfs->mkdir($dir))
+                       if($exportable != null)
+                       {
+                               if($excel_export)
                                {
-                                       return;
+                                       $export_data = 
$exportable->get_contents_excel();
+                                       //_debug_array($export_data[1]);
+                                       return $export_data;
                                }
-                       }
-                       
-                       
-                       $id = $billing_job->get_id();
-                       $export_data = $exportable->get_contents();
-                       $file_path = $path."/{$id}";
-                       if($export_data != ""){                 
-                               $result = $vfs->write
-                               (
-                                       array
-                                       (
-                                               'string' => $file_path,
-                                               RELATIVE_NONE,
-                                               'content' => $export_data
-                                       )
-                               );
-                               if($result)
+                               else
                                {
-                                       return true;
+                                       //$sql = "UPDATE rental_billing SET 
export_data = 
{$this->marshal(iconv("ISO-8859-1","UTF-8",$exportable->get_contents()),'string')}
 WHERE id = {$this->marshal($billing_job->get_id(),'int')}";
+                                       //$result = $this->db->query($sql, 
__LINE__, __FILE__);
+
+                                       $vfs                             = 
CreateObject('phpgwapi.vfs');
+                                       $vfs->override_acl       = 1;
+
+                                       $path    = "/rental";
+                                       $dir     = array('string' => $path, 
RELATIVE_NONE);
+                                       if(!$vfs->file_exists($dir))
+                                       {
+                                               if(!$vfs->mkdir($dir))
+                                               {
+                                                       return;
+                                               }
+                                       }
+
+                                       $path .= "/billings";
+                                       $dir = array('string' => $path, 
RELATIVE_NONE);
+                                       if(!$vfs->file_exists($dir))
+                                       {
+                                               if(!$vfs->mkdir($dir))
+                                               {
+                                                       return;
+                                               }
+                                       }
+
+
+                                       $id                      = 
$billing_job->get_id();
+                                       $export_data = 
$exportable->get_contents();
+                                       $file_path       = $path . "/{$id}";
+                                       if($export_data != "")
+                                       {
+                                               $result = $vfs->write
+                                               (
+                                                       array
+                                                       (
+                                                               'string'        
 => $file_path,
+                                                               RELATIVE_NONE,
+                                                               'content'       
 => $export_data
+                                                       )
+                                               );
+                                               if($result)
+                                               {
+                                                       return true;
+                                               }
+                                       }
                                }
                        }
-                    }
-               }       
-               return false;
-       }
-       
-       public function generate_customer_export($billing_id)
-       {
-               
-               $file = PHPGW_SERVER_ROOT . 
"/rental/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}/customer.php";
-               if(is_file($file))
-               {
-                       include $file;
-                       return $customer_export->get_contents();
+                       return false;
                }
-               else
+
+               public function generate_customer_export($billing_id)
                {
-                       $file = PHPGW_SERVER_ROOT . 
"/rental/inc/export/default/customer.php";
+
+                       $file = PHPGW_SERVER_ROOT . 
"/rental/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}/customer.php";
                        if(is_file($file))
                        {
                                include $file;
@@ -425,31 +435,39 @@
                        }
                        else
                        {
-                               return false;
+                               $file = PHPGW_SERVER_ROOT . 
"/rental/inc/export/default/customer.php";
+                               if(is_file($file))
+                               {
+                                       include $file;
+                                       return $customer_export->get_contents();
+                               }
+                               else
+                               {
+                                       return false;
+                               }
                        }
                }
-       }
-       
-       public function get_export_data(int $billing_job_id)
-       {
-               $sql = "SELECT export_data FROM rental_billing WHERE id = 
{$this->marshal($billing_job_id,'int')}";
-               $result = $this->db->query($sql, __LINE__, __FILE__);
-               if($result && $this->db->next_record())
+
+               public function get_export_data(int $billing_job_id)
                {
-                       return $this->unmarshal(iconv("UTF-8","ISO-8859-1", 
$this->db->f('export_data', true)), 'string');
+                       $sql     = "SELECT export_data FROM rental_billing 
WHERE id = {$this->marshal($billing_job_id, 'int')}";
+                       $result  = $this->db->query($sql, __LINE__, __FILE__);
+                       if($result && $this->db->next_record())
+                       {
+                               return $this->unmarshal(iconv("UTF-8", 
"ISO-8859-1", $this->db->f('export_data', true)), 'string');
+                       }
+                       return '';
                }
-               return '';
-       }
-       
-       public function get_agresso_export_format($contract_type)
-       {
-               $sql = "SELECT export_format FROM 
rental_contract_responsibility WHERE location_id=$contract_type";
-               $result = $this->db->query($sql, __LINE__, __FILE__);
-               if($result && $this->db->next_record())
+
+               public function get_agresso_export_format($contract_type)
                {
-                       return $this->unmarshal($this->db->f('export_format', 
true), 'string');
+                       $sql     = "SELECT export_format FROM 
rental_contract_responsibility WHERE location_id=$contract_type";
+                       $result  = $this->db->query($sql, __LINE__, __FILE__);
+                       if($result && $this->db->next_record())
+                       {
+                               return 
$this->unmarshal($this->db->f('export_format', true), 'string');
+                       }
+                       return '';
                }
-               return '';
-       }
-}
-?>
+
+       }
\ No newline at end of file

Modified: branches/Version-1_0-branch/rental/inc/class.socommon.inc.php
===================================================================
--- branches/Version-1_0-branch/rental/inc/class.socommon.inc.php       
2014-03-14 16:13:01 UTC (rev 11826)
+++ branches/Version-1_0-branch/rental/inc/class.socommon.inc.php       
2014-03-14 16:21:38 UTC (rev 11827)
@@ -14,6 +14,37 @@
                $this->left_join        = & $this->db->left_join;
        }
        
+               /**
+               * Begin transaction
+               *
+               * @return integer|boolean current transaction id
+               */
+               public function transaction_begin()
+               {
+                       return $this->db->transaction_begin();
+               }
+
+               /**
+               * Complete the transaction
+               *
+               * @return boolean True if sucessful, False if fails
+               */ 
+               public function transaction_commit()
+               {
+                       return $this->db->transaction_commit();
+               }
+
+               /**
+               * Rollback the current transaction
+               *
+               * @return boolean True if sucessful, False if fails
+               */
+               public function transaction_abort()
+               {
+                       return $this->db->transaction_abort();
+               }
+
+
        /**
         * Marshal values according to type
         * @param $value the value

Modified: branches/Version-1_0-branch/rental/inc/class.uibilling.inc.php
===================================================================
--- branches/Version-1_0-branch/rental/inc/class.uibilling.inc.php      
2014-03-14 16:13:01 UTC (rev 11826)
+++ branches/Version-1_0-branch/rental/inc/class.uibilling.inc.php      
2014-03-14 16:21:38 UTC (rev 11827)
@@ -25,7 +25,7 @@
                self::set_active_menu('rental::contracts::invoice');
                $config = CreateObject('phpgwapi.config','rental');
                $config->read();
-               $billing_time_limit = 
$config->config_data['billing_time_limit'];
+               $billing_time_limit = 
isset($config->config_data['billing_time_limit']) && 
$config->config_data['billing_time_limit'] ? 
(int)$config->config_data['billing_time_limit'] : 500;
                set_time_limit($billing_time_limit); // Set time limit
                $GLOBALS['phpgw_info']['flags']['app_header'] .= 
'::'.lang('invoice_menu');
        }

Modified: 
branches/Version-1_0-branch/rental/inc/model/class.agresso_lg04.inc.php
===================================================================
--- branches/Version-1_0-branch/rental/inc/model/class.agresso_lg04.inc.php     
2014-03-14 16:13:01 UTC (rev 11826)
+++ branches/Version-1_0-branch/rental/inc/model/class.agresso_lg04.inc.php     
2014-03-14 16:21:38 UTC (rev 11827)
@@ -1,499 +1,470 @@
 <?php
-phpgw::import_class('rental.socomposite'); 
-include_class('rental', 'exportable', 'inc/model/');
+       phpgw::import_class('rental.socomposite');
+       include_class('rental', 'exportable', 'inc/model/');
 
-class rental_agresso_lg04 implements rental_exportable
-{
-       protected $billing_job;
-       protected $date_str;
-       protected $orders;
-       
-       public function __construct($billing_job)
+       class rental_agresso_lg04 implements rental_exportable
        {
-               $this->billing_job = $billing_job;
-               $this->date_str = date('ymd', 
$billing_job->get_timestamp_stop());
-               $this->orders = null;
-       }
-       
-       /**
-        * @see rental_exportable
-        */
-       public function get_id()
-       {
-               return 'Agresso LG04';
-       }
-       
-       /**
-        * Returns the file contents as a string.
-        * 
-        * @see rental_exportable
-        */
-       public function get_contents()
-       {
-               $contents = '';
-               if($this->orders == null) // Data hasn't been created yet
+
+               protected $billing_job;
+               protected $date_str;
+               protected $orders;
+
+               public function __construct($billing_job)
                {
-                       $this->run();
+                       $this->billing_job       = $billing_job;
+                       $this->date_str          = date('ymd', 
$billing_job->get_timestamp_stop());
+                       $this->orders            = null;
                }
-               foreach($this->orders as $order)
+
+               /**
+                * @see rental_exportable
+                */
+               public function get_id()
                {
-                       foreach($order as $line)
+                       return 'Agresso LG04';
+               }
+
+               /**
+                * Returns the file contents as a string.
+                * 
+                * @see rental_exportable
+                */
+               public function get_contents()
+               {
+                       $contents = '';
+                       if($this->orders == null) // Data hasn't been created 
yet
                        {
-                               $contents .= "{$line}\n";
+                               $this->run();
                        }
+                       foreach($this->orders as $order)
+                       {
+                               foreach($order as $line)
+                               {
+                                       $contents .= "{$line}\n";
+                               }
+                       }
+                       return $contents;
                }
-               return $contents;
-       }
-        
-        public function get_contents_excel()
-       {
-               if($this->orders == null) // Data hasn't been created yet
+
+               public function get_contents_excel()
                {
-                       $this->run_excel_export();
+                       if($this->orders == null) // Data hasn't been created 
yet
+                       {
+                               $this->run_excel_export();
+                       }
+                       return $this->orders;
                }
-               return $this->orders;
-       }
-       
-       public function get_missing_billing_info($contract)
-       {
-               $missing_billing_info = array();
-               $contract_parties = $contract->get_parties();
-               if($contract_parties == null || count($contract_parties) < 1)
+
+               public function get_missing_billing_info($contract)
                {
-                       $missing_billing_info[] = 'Missing contract party.';
-               }
-               
-               $payer_id = $contract->get_payer_id();
-               if($payer_id == null || $payer_id = 0)
-               {
-                       $missing_billing_info[] = 'Missing payer id.';
-               }
-               
-               return $missing_billing_info;
-       }
-       
-       /**
-        * Does all the dirty work by building all the lines of Agresso contents
-        * from the billing job.
-        */
-       protected function run()
-       {
-               $this->orders = array();
-               $decimal_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'] 
: ',';
-               $thousands_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'] 
: '.'; 
-               // We need all invoices for this billing
-               $invoices = rental_soinvoice::get_instance()->get(null, null, 
'id', true, null, null, array('billing_id' => $this->billing_job->get_id()));
-               
-               
-               $config = CreateObject('phpgwapi.config','rental');
-               $config->read();
-               $serial_config_start = $config->config_data['serial_start'];
-               $serial_config_stop =  $config->config_data['serial_stop'];
-               
-               
-               if(     isset($serial_config_start) && 
is_numeric($serial_config_start) &&
-                       isset($serial_config_stop) && 
is_numeric($serial_config_stop))
-               {
-                       $max_serial_number_used = 
rental_soinvoice::get_instance()->get_max_serial_number_used($serial_config_start,
 $serial_config_stop);
-                       
-                       if(isset($max_serial_number_used) && 
is_numeric($max_serial_number_used) && $max_serial_number_used > 0 )
+                       $missing_billing_info    = array();
+                       $contract_parties                = 
$contract->get_parties();
+                       if($contract_parties == null || 
count($contract_parties) < 1)
                        {
-                               $serial_number = $max_serial_number_used + 1;
+                               $missing_billing_info[] = 'Missing contract 
party.';
                        }
-                       else
+
+                       $payer_id        = $contract->get_payer_id();
+                       if($payer_id == null || $payer_id        = 0)
                        {
-                               $serial_number = $serial_config_start;
+                               $missing_billing_info[] = 'Missing payer id.';
                        }
-                       
-                       $number_left_in_sequence = $serial_config_stop - 
$serial_number;
-                       
-                       if($number_left_in_sequence < count($invoices))
-                       {
-                               //var_dump("Out of sequence numbers");
-                               //Give error message (out of sequence numbers) 
and return
-                       }
+
+                       return $missing_billing_info;
                }
-               else
+
+               /**
+                * Does all the dirty work by building all the lines of Agresso 
contents
+                * from the billing job.
+                */
+               protected function run()
                {
-                       //var_dump("Not configured properly");
-                       //Give error message (not configured properly) and 
return
-               }
-               
-               foreach($invoices as $invoice) // Runs through all invoices
-               {
-                       // We need all price items in the invoice
-                       $price_items = 
rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null, 
null, array('invoice_id' => $invoice->get_id()));
-                       $composite_name = '';
-                       // We need to get the composites to get a composite 
name for the Agresso export
-                       $composites = 
rental_socomposite::get_instance()->get(null, null, null, null, null, null, 
array('contract_id' => $invoice->get_contract_id()));
-                       if($composites != null && count($composites) > 0)
+                       $this->orders            = array();
+                       $decimal_separator       = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'] 
: ',';
+                       $thousands_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'] 
: '.';
+                       // We need all invoices for this billing
+                       $invoices                        = 
rental_soinvoice::get_instance()->get(null, null, 'id', true, null, null, 
array('billing_id' => $this->billing_job->get_id()));
+
+
+                       $config                          = 
CreateObject('phpgwapi.config', 'rental');
+                       $config->read();
+                       $serial_config_start = 
$config->config_data['serial_start'];
+                       $serial_config_stop      = 
$config->config_data['serial_stop'];
+
+
+                       if(isset($serial_config_start) && 
is_numeric($serial_config_start) &&
+                       isset($serial_config_stop) && 
is_numeric($serial_config_stop))
                        {
-                               $keys = array_keys($composites);
-                               $composite_name = 
$composites[$keys[0]]->get_name();
+                               $max_serial_number_used = 
rental_soinvoice::get_instance()->get_max_serial_number_used($serial_config_start,
 $serial_config_stop);
+
+                               if(isset($max_serial_number_used) && 
is_numeric($max_serial_number_used) && $max_serial_number_used > 0)
+                               {
+                                       $serial_number = 
$max_serial_number_used + 1;
+                               }
+                               else
+                               {
+                                       $serial_number = $serial_config_start;
+                               }
+
+                               $number_left_in_sequence = $serial_config_stop 
- $serial_number;
+
+                               if($number_left_in_sequence < count($invoices))
+                               {
+                                       //var_dump("Out of sequence numbers");
+                                       //Give error message (out of sequence 
numbers) and return
+                               }
                        }
-                       // HACK to get the needed location code for the building
-                       $building_location_code = 
rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
-                       
-                       $price_item_data = array();
-                       foreach($price_items as $price_item) // Runs through 
all items
+                       else
                        {
-                               $data = array();
-                               $data['amount'] = 
$price_item->get_total_price();
-                               $description = $price_item->get_title();
-                               $start = $price_item->get_timestamp_start();
-                               $stop = $price_item->get_timestamp_end();
-                               if(isset($start) && isset($stop))
+                               //var_dump("Not configured properly");
+                               //Give error message (not configured properly) 
and return
+                       }
+
+                       foreach($invoices as $invoice) // Runs through all 
invoices
+                       {
+                               // We need all price items in the invoice
+                               $price_items     = 
rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null, 
null, array('invoice_id' => $invoice->get_id()));
+                               $composite_name  = '';
+                               // We need to get the composites to get a 
composite name for the Agresso export
+                               $composites              = 
rental_socomposite::get_instance()->get(null, null, null, null, null, null, 
array('contract_id' => $invoice->get_contract_id()));
+                               if($composites != null && count($composites) > 
0)
                                {
-                                       $description .= ' 
'.date('j/n',$start).'-'.date('j/n',$stop);
+                                       $keys                    = 
array_keys($composites);
+                                       $composite_name  = 
$composites[$keys[0]]->get_name();
                                }
-                               $data['article_description'] = $description;
-                               $data['article_code'] = 
$price_item->get_agresso_id();
-                               $price_item_data[] = $data;
+                               // HACK to get the needed location code for the 
building
+                               $building_location_code = 
rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
+
+                               $price_item_data = array();
+                               foreach($price_items as $price_item) // Runs 
through all items
+                               {
+                                       $data                    = array();
+                                       $data['amount']  = 
$price_item->get_total_price();
+                                       $description     = 
$price_item->get_title();
+                                       $start                   = 
$price_item->get_timestamp_start();
+                                       $stop                    = 
$price_item->get_timestamp_end();
+                                       if(isset($start) && isset($stop))
+                                       {
+                                               $description .= ' ' . 
date('j/n', $start) . '-' . date('j/n', $stop);
+                                       }
+                                       $data['article_description'] = 
$description;
+                                       $data['article_code']            = 
$price_item->get_agresso_id();
+                                       $price_item_data[]                      
 = $data;
+                               }
+                               $this->orders[] = 
$this->get_order($invoice->get_header(), 
$invoice->get_party()->get_identifier(), $invoice->get_id(), 
$this->billing_job->get_year(), $this->billing_job->get_month(), 
$invoice->get_account_out(), $price_item_data, 
$invoice->get_responsibility_id(), $invoice->get_service_id(), 
$building_location_code, $invoice->get_project_id(), $composite_name, 
$serial_number, $invoice->get_reference());
+                               $invoice->set_serial_number($serial_number);
+                               $serial_number++;
                        }
-                       $this->orders[] = $this->get_order(
-                               $invoice->get_header(), 
-                               $invoice->get_party()->get_identifier(), 
-                               $invoice->get_id(), 
-                               $this->billing_job->get_year(), 
-                               $this->billing_job->get_month(), 
-                               $invoice->get_account_out(), 
-                               $price_item_data, 
-                               $invoice->get_responsibility_id(), 
-                               $invoice->get_service_id(), 
-                               $building_location_code, 
-                               $invoice->get_project_id(), 
-                               $composite_name,
-                               $serial_number,
-                               $invoice->get_reference()
-                       );
-                       $invoice->set_serial_number($serial_number);
-                       $serial_number++;
+
+                       $so_invoice = rental_soinvoice::get_instance();
+
+                       $so_invoice->transaction_begin();
+                       //Store invoices with serial numbers
+                       foreach($invoices as $invoice) // Runs through all 
invoices
+                       {
+                               $so_invoice->store($invoice);
+                       }
+                       return $so_invoice->transaction_commit();
                }
-               
-               $so_invoice = rental_soinvoice::get_instance();
-               
-               //Store invoices with serial numbers
-               foreach($invoices as $invoice) // Runs through all invoices
+
+               protected function run_excel_export()
                {
-                       $so_invoice->store($invoice);
-               }
-       }
-        
-        protected function run_excel_export()
-       {
-               $this->orders = array();
-               $decimal_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'] 
: ',';
-               $thousands_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'] 
: '.'; 
-               // We need all invoices for this billing
-               $invoices = rental_soinvoice::get_instance()->get(null, null, 
'id', true, null, null, array('billing_id' => $this->billing_job->get_id()));
-               
-               foreach($invoices as $invoice) // Runs through all invoices
-               {
-                       // We need all price items in the invoice
-                       $price_items = 
rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null, 
null, array('invoice_id' => $invoice->get_id()));
-                       $composite_name = '';
-                       // We need to get the composites to get a composite 
name for the Agresso export
-                       $composites = 
rental_socomposite::get_instance()->get(null, null, null, null, null, null, 
array('contract_id' => $invoice->get_contract_id()));
-                       if($composites != null && count($composites) > 0)
+                       $this->orders            = array();
+                       $decimal_separator       = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['rental']['decimal_separator'] 
: ',';
+                       $thousands_separator = 
isset($GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['rental']['thousands_separator'] 
: '.';
+                       // We need all invoices for this billing
+                       $invoices                        = 
rental_soinvoice::get_instance()->get(null, null, 'id', true, null, null, 
array('billing_id' => $this->billing_job->get_id()));
+
+                       foreach($invoices as $invoice) // Runs through all 
invoices
                        {
-                               $keys = array_keys($composites);
-                               $composite_name = 
$composites[$keys[0]]->get_name();
-                       }
-                       // HACK to get the needed location code for the building
-                       $building_location_code = 
rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
-                       
-                       $price_item_data = array();
-            $price_item_counter = 0;
-                       foreach($price_items as $price_item) // Runs through 
all items
-                       {
-                               $data = array();
-                               $data['amount'] = 
$price_item->get_total_price();
-                               $description = $price_item->get_title();
-                               $start = $price_item->get_timestamp_start();
-                               $stop = $price_item->get_timestamp_end();
-                               if(isset($start) && isset($stop))
+                               // We need all price items in the invoice
+                               $price_items     = 
rental_soinvoice_price_item::get_instance()->get(null, null, null, null, null, 
null, array('invoice_id' => $invoice->get_id()));
+                               $composite_name  = '';
+                               // We need to get the composites to get a 
composite name for the Agresso export
+                               $composites              = 
rental_socomposite::get_instance()->get(null, null, null, null, null, null, 
array('contract_id' => $invoice->get_contract_id()));
+                               if($composites != null && count($composites) > 
0)
                                {
-                                       $description .= ' 
'.date('j/n',$start).'-'.date('j/n',$stop);
+                                       $keys                    = 
array_keys($composites);
+                                       $composite_name  = 
$composites[$keys[0]]->get_name();
                                }
-                               $data['article_description'] = $description;
-                               $data['article_code'] = 
$price_item->get_agresso_id();
-                               $price_item_data[] = $data;
-                
-                $serialized_party = $invoice->get_party()->serialize();
-                $party_name = $serialized_party['name'];
-                        
-                $this->orders[] = $this->get_order_excel(
-                    $invoice->get_header(), 
-                    $invoice->get_party()->get_identifier(),
-                    $party_name,
-                    $invoice->get_id(), 
-                    $this->billing_job->get_year(), 
-                    $this->billing_job->get_month(), 
-                    $invoice->get_account_out(), 
-                    $data, 
-                    $invoice->get_responsibility_id(), 
-                    $invoice->get_service_id(), 
-                    $building_location_code, 
-                    $invoice->get_project_id(), 
-                    $composite_name,
-                    $invoice->get_reference(),
-                    $price_item_counter
-                );
-                $price_item_counter++;
+                               // HACK to get the needed location code for the 
building
+                               $building_location_code = 
rental_socomposite::get_instance()->get_building_location_code($invoice->get_contract_id());
+
+                               $price_item_data         = array();
+                               $price_item_counter      = 0;
+                               foreach($price_items as $price_item) // Runs 
through all items
+                               {
+                                       $data                    = array();
+                                       $data['amount']  = 
$price_item->get_total_price();
+                                       $description     = 
$price_item->get_title();
+                                       $start                   = 
$price_item->get_timestamp_start();
+                                       $stop                    = 
$price_item->get_timestamp_end();
+                                       if(isset($start) && isset($stop))
+                                       {
+                                               $description .= ' ' . 
date('j/n', $start) . '-' . date('j/n', $stop);
+                                       }
+                                       $data['article_description'] = 
$description;
+                                       $data['article_code']            = 
$price_item->get_agresso_id();
+                                       $price_item_data[]                      
 = $data;
+
+                                       $serialized_party        = 
$invoice->get_party()->serialize();
+                                       $party_name                      = 
$serialized_party['name'];
+
+                                       $this->orders[] = 
$this->get_order_excel(
+                                       $invoice->get_header(), 
$invoice->get_party()->get_identifier(), $party_name, $invoice->get_id(), 
$this->billing_job->get_year(), $this->billing_job->get_month(), 
$invoice->get_account_out(), $data, $invoice->get_responsibility_id(), 
$invoice->get_service_id(), $building_location_code, 
$invoice->get_project_id(), $composite_name, $invoice->get_reference(), 
$price_item_counter
+                                       );
+                                       $price_item_counter++;
+                               }
                        }
                }
-       }
-       
-       /**
-        * Builds one single order of the Agresso file.
-        * 
-        */
-       protected function get_order($header, $party_id, $order_id, $bill_year, 
$bill_month, $account, $product_items, $responsibility, $service, $building, 
$project, $text, $serial_number, $client_ref)
-       {
-               
-               //$order_id = $order_id + 39500000;
-               // XXX: Which charsets do Agresso accept/expect? Do we need to 
something regarding padding and UTF-8?
-               $order = array();
-               
-               
-               $order[] =  // Header line
-                        '1'                                                    
                                                        //  1           
accept_flag
-                       .sprintf("%8s", '')                                     
                                                //      2               just 
white space..
-                       .sprintf("%20s", '')                                    
                                        //  3           accountable
-                       .sprintf("%160s", '')                                   
                                        //  4           address
-                       .sprintf("%20s", '')                                    
                                        //      5-7             just white 
space..
-                       .sprintf("%08s", '')                                    
                                        //  8           apar_id
-                       .sprintf("%30s", '')                                    
                                        //  9           apar_name
-                       .sprintf("%50s", '')                                    
                                        //      10-11   just white space..
-                       .sprintf("%2s", '')                                     
                                                //      12              att_1_id
-                       .sprintf("%2s", '')                                     
                                                //      13              att_2_id
-                       .sprintf("%2s", '')                                     
                                                //      14              att_3_id
-                       .sprintf("%2s", '')                                     
                                                //      15              att_4_id
-                       .sprintf("%2s", '')                                     
                                                //      16              att_5_id
-                       .sprintf("%2s", '')                                     
                                                //      17              att_6_id
-                       .sprintf("%2s", '')                                     
                                                //      18              att_7_id
-                       .sprintf("%35s", '')                                    
                                        //      19              bank_account
-                       .sprintf("%-12s", "BKBPE{$this->date_str}")             
                        //      20              batch_id                        
        DATA
-                       .'BY'                                                   
                                                        //      21              
client                                  DATA
-                       .sprintf("%2s", '')                                     
                                                //      22              
client_ref
-                       .sprintf("%-17s", "{$this->date_str}")                  
                        //      23              confirm_date                    
DATA
-                       .sprintf("%1s", '')                                     
                                                //      24              control
-                       .sprintf("%17s", '')                                    
                                        //      25              just white 
space..
-                       .'NOK'                                                  
                                                        //      26              
currency                                DATA
-                       .sprintf("%60s", '')                                    
                                        //      27              del_met_descr
-                       .sprintf("%60s", '')                                    
                                        //      28              del_term_descr
-                       .sprintf("%255s", '')                                   
                                        //      29              deliv_addr
-                       .sprintf("%50s", '')                                    
                                        //      30              deliv_attention
-                       .sprintf("%3s", '')                                     
                                                //      31              
deliv_countr
-                       .sprintf("%-17s", "{$this->date_str}")                  
                        //      32              deliv_date                      
        DATA
-                       .sprintf("%8s", '')                                     
                                                //      33              
deliv_method
-                       .sprintf("%8s", '')                                     
                                                //      34              
deliv_terms
-                       .sprintf("%52s", '')                                    
                                        //      35-41   just white space..
-                       .sprintf("%-12.12s", $account)                          
                                //      42              dim_value_1             
                DATA
-                       .sprintf("%12s", '')                                    
                                        //      43              dim_value_2
-                       .sprintf("%12s", '')                                    
                                        //      44              dim_value_3
-                       .sprintf("%12s", '')                                    
                                        //      45              dim_value_4
-                       .sprintf("%12s", '')                                    
                                        //      46              dim_value_5
-                       .sprintf("%12s", '')                                    
                                        //      47              dim_value_6     
-                       .sprintf("%12s", '')                                    
                                        //      48              dim_value_7
-                       .sprintf("%17s", '')                                    
                                        //      49-50   just white space..
-                       .sprintf("%017s", '')                                   
                                        //      51              exch_rate
-                       .sprintf("%-15.15s", $client_ref)                       
                                //      52              ext_ord_ref
-                       .sprintf("%6s", '')                                     
                                                //      53              
intrule_id
-                       .sprintf("%8s", '')                                     
                                                //      54-55   just white 
space..
-                       .sprintf("%-120.120s", utf8_decode($header))            
                //      56              long_info1                              
DATA
-                       .sprintf("%120s", '')                                   
                                        //      57              long_info2
-                       .sprintf("%10s", '')                                    
                                        //      58              just white 
space..
-                       .sprintf("%08s", '')                                    
                                        //      59              main_apar_id
-                       .sprintf("%50s", '')                                    
                                        //      60              mark_attention
-                       .sprintf("%3s", '')                                     
                                                //      61              
mark_ctry_cd
-                       .sprintf("%120s", '')                                   
                                        //      62              markings
-                       .sprintf("%-17s", '')                                   
                                        //      63              obs_date
-                       .sprintf("%-17s", '')                                   
                                        //      64              order_date
-                       .sprintf("%09.9s", $serial_number)                      
                                //      65              order_id                
                DATA
-                       .'FS'                                                   
                                                        //      66              
order_type                              DATA
-                       .'IP'                                                   
                                                        //      67              
pay_method                              DATA
-                                                                               
                                                                //      (68)
-                       .sprintf("%02s", '')
-                       .sprintf("%04.4s", $bill_year)
-                       .sprintf("%02.2s", $bill_month)                         
                                //      69              period                  
                DATA
-                       .sprintf("%30s", '')                                    
                                        //      70              place
-                       .sprintf("%40s", '')                                    
                                        //      71              province
-                       .sprintf("%12s", '')                                    
                                        //      72              just white 
space..
-                       .sprintf("%-8s", 'BKBPE')                               
                                        //      73              responsible     
                        DATA
-                       .sprintf("%-8s", 'BKBPE')                               
                                        //      74              responsible2    
                DATA
-                       .sprintf("%8s", '')                                     
                                                //      75              just 
white space..
-                       .sprintf("%-08s", '')                                   
                                        //      76              sequence_ref
-                       .sprintf("%80s", '')                                    
                                        //      77-78   just white space..
-                       .'N'                                                    
                                                        //      79              
status                                  DATA
-                       .sprintf("%4s", '')                                     
                                                //      80-82   just white 
space..
-                       .sprintf("%08s", '')                                    
                                        //      83              template_id
-                       .sprintf("%2s", '')                                     
                                                //      84              terms_id
-                       .sprintf("%12s", '')                                    
                                        //      85              tekx1
-                       .sprintf("%-12s", $party_id)                            
                                //      86              tekst2                  
                DATA
-                       .sprintf("%12s", '')                                    
                                        //      87              tekst3
-                       .sprintf("%12s", '')                                    
                                        //      88              text4
-                       .'42'                                                   
                                                        //      89              
trans_type                              DATA
-                       .sprintf("%70s", '')                                    
                                        //      90-92   just white space..
-                       .sprintf("%09s", '')                                    
                                        //      93              voucher_ref
-                       .'FU'                                                   
                                                        //      94              
voucher_type                    DATA
-                       .sprintf("%4s", '')                                     
                                                //      95              just 
white space..
-                       .sprintf("%15s", '')                                    
                                        //      96              zip_code
-               ;
-               $item_counter = 0;
-               foreach($product_items as $item) // All products (=price items)
+
+               /**
+                * Builds one single order of the Agresso file.
+                * 
+                */
+               protected function get_order($header, $party_id, $order_id, 
$bill_year, $bill_month, $account, $product_items, $responsibility, $service, 
$building, $project, $text, $serial_number, $client_ref)
                {
-                       $order[] = // Product line
-                               '0'                                             
                                                                //      1       
        0 for påfølgende linjer etter ordrehde
-                               .sprintf("%8s", '')                             
                                                //  2           account
-                               .sprintf("%180s", '')                           
                                        //      3-4             just white 
space..
-                               .sprintf("%2s", '')                             
                                                //  5           allocation_key
-                               .$this->get_formatted_amount($item['amount'])   
                //  6           amount                                  DATA
-                               .'1'                                            
                                                        //  7           
amount_set
-                               .sprintf("%38s", '')                            
                                        //      8-9             just white 
space..
-                               .sprintf("%-35.35s", 
utf8_decode($item['article_description']))         //      10      art_descr    
           DATA
-                               .sprintf("%-15.15s", $item['article_code'])     
                        //      11              article                         
        DATA
-                               .sprintf("%49s", '')                            
                                        //      12-19   just white space..
-                               .sprintf("%-12s", "BKBPE{$this->date_str}")     
                        //      20              batch_id                        
        DATA
-                               .'BY'                                           
                                                        //      21              
client                                  DATA
-                               .sprintf("%20s", '')                            
                                        //      22-24   just white space..
-                               .sprintf("%017s", '')                           
                                        //      25              cur_amount
-                               .sprintf("%464s", '')                           
                                        //      26-34   just white space..
-                               .sprintf("%-8.8s", $responsibility)             
                                //      35              dim_1                   
                DATA
-                               .sprintf("%-8.8s", $service)                    
                                //      36              dim_2                   
                DATA
-                               .sprintf("%8s", '')                             
                                                //      37              dim_3
-                               .sprintf("%8s", '')                             
                                                //      38              dim_4
-                               .sprintf("%-12.12s", $project)                  
                                //      39              dim_5                   
                DATA
-                               .sprintf("%4s", '')                             
                                                //      40              dim_6
-                               .sprintf("%4s", '')                             
                                                //      41              dim_7
-                               .sprintf("%84s", '')                            
                                        //      42-48   just white space..
-                               .sprintf("%017s", '')                           
                                        //      49              disc_percent
-                                                                               
                                                                //      (50)
-                               .sprintf("%017s", '')                           
                                        //      51              exch_rate
-                               .sprintf("%21s", '')                            
                                        //      52-53   just white space..
-                               .sprintf("%04.4s", ++$item_counter)             
                                //      54              line_no                 
                DATA
-                               .sprintf("%4s", '')                             
                                                //      55              location
-                               .sprintf("%240s", '')                           
                                        //      56-57   just white space..
-                               .sprintf("%10s", '')                            
                                        //      58              lot
-                               .sprintf("%215s", '')                           
                                        //      59-64   just white space..
-                               .sprintf("%09.9s", $serial_number)              
                                //      65      order_id                        
                DATA
-                               .sprintf("%4s", '')                             
                                                //      66-67   just white 
space..
-                                                                               
                                                                //      (68)
-                               .sprintf("%02s", '')
-                               .sprintf("%04.4s", $bill_year)
-                               .sprintf("%02.2s", $bill_month)                 
                                //      69              period                  
                DATA
-                               .sprintf("%70s", '')                            
                                        //      70-71   just white space..
-                               .sprintf("%12s", '')                            
                                        //      72              rel_value
-                               .sprintf("%16s", '')                            
                                        //      73-74   just white space..
-                               .sprintf("%08s", '')                            
                                        //      75              sequence_no
-                               .sprintf("%8s", '')                             
                                                //      76              just 
white space..
-                               .sprintf("%20s", '')                            
                                        //      77              serial_no
-                               .sprintf("%60s", '')                            
                                        //      78              just white 
space..
-                               .'N'                                            
                                                        //      79              
status                                  DATA
-                                                                               
                                                                //      (80)
-                               .sprintf("%2s", '')                             
                                                //      81              tax_code
-                               .sprintf("%2s", '')                             
                                                //      82              
tax_system
-                               .sprintf("%-08s", '')                           
                                        //      83              template_id
-                               .sprintf("%50s", '')                            
                                        //      84-88   just white space..
-                               .'42'                                           
                                                        //      89              
trans_type
-                               .sprintf("%3s", '')                             
                                                //      90              
unit_code
-                               .sprintf("%50s", '')                            
                                        //      91              unit_descr
-                               .sprintf("%017s", 1*100)                        
                                        //      92              value_1         
                        DATA
-                               .sprintf("%9s", '')                             
                                                //      93              just 
white space..
-                               .'FU'                                           
                                                        //      94              
voucher_type                    DATA
-                               .sprintf("%4s", '')                             
                                                //      95              
warehouse
-                               .sprintf("%15s", '')                            
                                        //      96              just white 
space..
+
+                       //$order_id = $order_id + 39500000;
+                       // XXX: Which charsets do Agresso accept/expect? Do we 
need to something regarding padding and UTF-8?
+                       $order = array();
+
+
+                       $order[]                 = // Header line
+                       '1'      //  1          accept_flag
+                       . sprintf("%8s", '')     //     2               just 
white space..
+                       . sprintf("%20s", '')   //  3           accountable
+                       . sprintf("%160s", '')  //  4           address
+                       . sprintf("%20s", '')   //      5-7             just 
white space..
+                       . sprintf("%08s", '')   //  8           apar_id
+                       . sprintf("%30s", '')   //  9           apar_name
+                       . sprintf("%50s", '')   //      10-11   just white 
space..
+                       . sprintf("%2s", '')     //     12              att_1_id
+                       . sprintf("%2s", '')     //     13              att_2_id
+                       . sprintf("%2s", '')     //     14              att_3_id
+                       . sprintf("%2s", '')     //     15              att_4_id
+                       . sprintf("%2s", '')     //     16              att_5_id
+                       . sprintf("%2s", '')     //     17              att_6_id
+                       . sprintf("%2s", '')     //     18              att_7_id
+                       . sprintf("%35s", '')   //      19              
bank_account
+                       . sprintf("%-12s", "BKBPE{$this->date_str}")  //        
20              batch_id                                DATA
+                       . 'BY'   //     21              client                  
                DATA
+                       . sprintf("%2s", '')     //     22              
client_ref
+                       . sprintf("%-17s", "{$this->date_str}")   //    23      
        confirm_date                    DATA
+                       . sprintf("%1s", '')     //     24              control
+                       . sprintf("%17s", '')   //      25              just 
white space..
+                       . 'NOK'  //     26              currency                
                DATA
+                       . sprintf("%60s", '')   //      27              
del_met_descr
+                       . sprintf("%60s", '')   //      28              
del_term_descr
+                       . sprintf("%255s", '')  //      29              
deliv_addr
+                       . sprintf("%50s", '')   //      30              
deliv_attention
+                       . sprintf("%3s", '')     //     31              
deliv_countr
+                       . sprintf("%-17s", "{$this->date_str}")   //    32      
        deliv_date                              DATA
+                       . sprintf("%8s", '')     //     33              
deliv_method
+                       . sprintf("%8s", '')     //     34              
deliv_terms
+                       . sprintf("%52s", '')   //      35-41   just white 
space..
+                       . sprintf("%-12.12s", $account)  //     42              
dim_value_1                             DATA
+                       . sprintf("%12s", '')   //      43              
dim_value_2
+                       . sprintf("%12s", '')   //      44              
dim_value_3
+                       . sprintf("%12s", '')   //      45              
dim_value_4
+                       . sprintf("%12s", '')   //      46              
dim_value_5
+                       . sprintf("%12s", '')   //      47              
dim_value_6     
+                       . sprintf("%12s", '')   //      48              
dim_value_7
+                       . sprintf("%17s", '')   //      49-50   just white 
space..
+                       . sprintf("%017s", '')  //      51              
exch_rate
+                       . sprintf("%-15.15s", $client_ref)      //      52      
        ext_ord_ref
+                       . sprintf("%6s", '')     //     53              
intrule_id
+                       . sprintf("%8s", '')     //     54-55   just white 
space..
+                       . sprintf("%-120.120s", utf8_decode($header)) //        
56              long_info1                              DATA
+                       . sprintf("%120s", '')  //      57              
long_info2
+                       . sprintf("%10s", '')   //      58              just 
white space..
+                       . sprintf("%08s", '')   //      59              
main_apar_id
+                       . sprintf("%50s", '')   //      60              
mark_attention
+                       . sprintf("%3s", '')     //     61              
mark_ctry_cd
+                       . sprintf("%120s", '')  //      62              markings
+                       . sprintf("%-17s", '')  //      63              obs_date
+                       . sprintf("%-17s", '')  //      64              
order_date
+                       . sprintf("%09.9s", $serial_number)     //      65      
        order_id                                DATA
+                       . 'FS'   //     66              order_type              
                DATA
+                       . 'IP'   //     67              pay_method              
                DATA
+                       //      (68)
+                       . sprintf("%02s", '')
+                       . sprintf("%04.4s", $bill_year)
+                       . sprintf("%02.2s", $bill_month)  //    69              
period                                  DATA
+                       . sprintf("%30s", '')   //      70              place
+                       . sprintf("%40s", '')   //      71              province
+                       . sprintf("%12s", '')   //      72              just 
white space..
+                       . sprintf("%-8s", 'BKBPE')   //         73              
responsible                             DATA
+                       . sprintf("%-8s", 'BKBPE')   //         74              
responsible2                    DATA
+                       . sprintf("%8s", '')     //     75              just 
white space..
+                       . sprintf("%-08s", '')  //      76              
sequence_ref
+                       . sprintf("%80s", '')   //      77-78   just white 
space..
+                       . 'N'    //     79              status                  
                DATA
+                       . sprintf("%4s", '')     //     80-82   just white 
space..
+                       . sprintf("%08s", '')   //      83              
template_id
+                       . sprintf("%2s", '')     //     84              terms_id
+                       . sprintf("%12s", '')   //      85              tekx1
+                       . sprintf("%-12s", $party_id)  //       86              
tekst2                                  DATA
+                       . sprintf("%12s", '')   //      87              tekst3
+                       . sprintf("%12s", '')   //      88              text4
+                       . '42'   //     89              trans_type              
                DATA
+                       . sprintf("%70s", '')   //      90-92   just white 
space..
+                       . sprintf("%09s", '')   //      93              
voucher_ref
+                       . 'FU'   //     94              voucher_type            
        DATA
+                       . sprintf("%4s", '')     //     95              just 
white space..
+                       . sprintf("%15s", '')   //      96              zip_code
                        ;
-                       $order[] = // Text line
-                               '0'.                                            
                                                        //      1
-                                sprintf("%345s", '')                           
                                        //      2-19    just white space..      
        DATA
-                               .sprintf("%-12s", "BKBPE{$this->date_str}")     
                        //      20              batch_id                        
        DATA
-                               .'BY'                                           
                                                        //      21              
client                                  DATA
-                               .sprintf("%692s", '')                           
                                        //      22-53   just white space..
-                               .sprintf("%04.4s", $item_counter)               
                                //      54              line_no                 
                DATA
-                               .sprintf("%469s", '')                           
                                        //      55-64   just white space..
-                               .sprintf("%09.9s", $serial_number)              
                                //      65              order_id                
                DATA
-                               .sprintf("%110s", '')                           
                                        //      66-74   just white space..
-                               .sprintf("%08s", 1)                             
                                                //      75              
sequence_no                             DATA
-                               .sprintf("%28s", '')                            
                                        //      76-77   just white space..
-                               .sprintf("%-60.60s", utf8_decode($text))        
                        //      78              shot_info                       
        DATA
-                               .sprintf("%63s", '')                            
                                        //      79-88   just white space..
-                               .'42'                                           
                                                        //      89              
trans_type                              DATA
-                               .sprintf("%79s", '')                            
                                        //      90-93   just white space..
-                               .'FU'                                           
                                                        //      94              
voucher_type                    DATA
-                               .sprintf("%19s", '')                            
                                        //      95-96   just white space..
-                       ;
+                       $item_counter    = 0;
+                       foreach($product_items as $item) // All products 
(=price items)
+                       {
+                               $order[] = // Product line
+                               '0'      //     1               0 for 
påfølgende linjer etter ordrehde
+                               . sprintf("%8s", '')    //  2           account
+                               . sprintf("%180s", '')   //     3-4             
just white space..
+                               . sprintf("%2s", '')    //  5           
allocation_key
+                               . $this->get_formatted_amount($item['amount'])  
 //  6          amount                                  DATA
+                               . '1'   //  7           amount_set
+                               . sprintf("%38s", '')   //      8-9             
just white space..
+                               . sprintf("%-35.35s", 
utf8_decode($item['article_description']))  //    10      art_descr             
  DATA
+                               . sprintf("%-15.15s", $item['article_code']) // 
        11              article                                 DATA
+                               . sprintf("%49s", '')   //      12-19   just 
white space..
+                               . sprintf("%-12s", "BKBPE{$this->date_str}") // 
        20              batch_id                                DATA
+                               . 'BY'  //      21              client          
                        DATA
+                               . sprintf("%20s", '')   //      22-24   just 
white space..
+                               . sprintf("%017s", '')   //     25              
cur_amount
+                               . sprintf("%464s", '')   //     26-34   just 
white space..
+                               . sprintf("%-8.8s", $responsibility)   //       
35              dim_1                                   DATA
+                               . sprintf("%-8.8s", $service)   //      36      
        dim_2                                   DATA
+                               . sprintf("%8s", '')    //      37              
dim_3
+                               . sprintf("%8s", '')    //      38              
dim_4
+                               . sprintf("%-12.12s", $project) //      39      
        dim_5                                   DATA
+                               . sprintf("%4s", '')    //      40              
dim_6
+                               . sprintf("%4s", '')    //      41              
dim_7
+                               . sprintf("%84s", '')   //      42-48   just 
white space..
+                               . sprintf("%017s", '')   //     49              
disc_percent
+                               //      (50)
+                               . sprintf("%017s", '')   //     51              
exch_rate
+                               . sprintf("%21s", '')   //      52-53   just 
white space..
+                               . sprintf("%04.4s", ++$item_counter)   //       
54              line_no                                 DATA
+                               . sprintf("%4s", '')    //      55              
location
+                               . sprintf("%240s", '')   //     56-57   just 
white space..
+                               . sprintf("%10s", '')   //      58              
lot
+                               . sprintf("%215s", '')   //     59-64   just 
white space..
+                               . sprintf("%09.9s", $serial_number)   //        
65      order_id                                        DATA
+                               . sprintf("%4s", '')    //      66-67   just 
white space..
+                               //      (68)
+                               . sprintf("%02s", '')
+                               . sprintf("%04.4s", $bill_year)
+                               . sprintf("%02.2s", $bill_month)        //      
69              period                                  DATA
+                               . sprintf("%70s", '')   //      70-71   just 
white space..
+                               . sprintf("%12s", '')   //      72              
rel_value
+                               . sprintf("%16s", '')   //      73-74   just 
white space..
+                               . sprintf("%08s", '')   //      75              
sequence_no
+                               . sprintf("%8s", '')    //      76              
just white space..
+                               . sprintf("%20s", '')   //      77              
serial_no
+                               . sprintf("%60s", '')   //      78              
just white space..
+                               . 'N'   //      79              status          
                        DATA
+                               //      (80)
+                               . sprintf("%2s", '')    //      81              
tax_code
+                               . sprintf("%2s", '')    //      82              
tax_system
+                               . sprintf("%-08s", '')   //     83              
template_id
+                               . sprintf("%50s", '')   //      84-88   just 
white space..
+                               . '42'  //      89              trans_type
+                               . sprintf("%3s", '')    //      90              
unit_code
+                               . sprintf("%50s", '')   //      91              
unit_descr
+                               . sprintf("%017s", 1 * 100)  //         92      
        value_1                                 DATA
+                               . sprintf("%9s", '')    //      93              
just white space..
+                               . 'FU'  //      94              voucher_type    
                DATA
+                               . sprintf("%4s", '')    //      95              
warehouse
+                               . sprintf("%15s", '')   //      96              
just white space..
+                               ;
+                               $order[] = // Text line
+                               '0' . //        1
+                               sprintf("%345s", '')   //       2-19    just 
white space..              DATA
+                               . sprintf("%-12s", "BKBPE{$this->date_str}") // 
        20              batch_id                                DATA
+                               . 'BY'  //      21              client          
                        DATA
+                               . sprintf("%692s", '')   //     22-53   just 
white space..
+                               . sprintf("%04.4s", $item_counter)   //         
54              line_no                                 DATA
+                               . sprintf("%469s", '')   //     55-64   just 
white space..
+                               . sprintf("%09.9s", $serial_number)   //        
65              order_id                                DATA
+                               . sprintf("%110s", '')   //     66-74   just 
white space..
+                               . sprintf("%08s", 1)    //      75              
sequence_no                             DATA
+                               . sprintf("%28s", '')   //      76-77   just 
white space..
+                               . sprintf("%-60.60s", utf8_decode($text)) //    
78              shot_info                               DATA
+                               . sprintf("%63s", '')   //      79-88   just 
white space..
+                               . '42'  //      89              trans_type      
                        DATA
+                               . sprintf("%79s", '')   //      90-93   just 
white space..
+                               . 'FU'  //      94              voucher_type    
                DATA
+                               . sprintf("%19s", '')   //      95-96   just 
white space..
+                               ;
+                       }
+                       return str_replace(array("\n", "\r"), '', $order);
                }
-               return str_replace(array("\n", "\r"), '', $order);
-       }
-        
-        /**
-        * Builds one single order of the excel file.
-        * 
-        */
-       protected function get_order_excel($header, $party_id, $party_name, 
$order_id, $bill_year, $bill_month, $account, $product_item, $responsibility, 
$service, $building, $project, $text, $client_ref, $counter)
-       {
-               
-               //$order_id = $order_id + 39500000;
-               // XXX: Which charsets do Agresso accept/expect? Do we need to 
something regarding padding and UTF-8?
-               //$order = array();
-               
-               $item_counter = $counter;
-        $order = array(
-            'account' => $account,
-            'client_ref' => $client_ref,
-            'header' => utf8_decode($header),
-            'bill_year' => $bill_year,
-            'bill_month' => $bill_month,
-            'Ansvar' => 'BKBPE',
-            'Ansvar2' => 'BKBPE',
-            'Party' => $party_id,
-            'name' => $party_name,
-            'amount' => 
$this->get_formatted_amount_excel($product_item['amount']),
+
+               /**
+                * Builds one single order of the excel file.
+                * 
+                */
+               protected function get_order_excel($header, $party_id, 
$party_name, $order_id, $bill_year, $bill_month, $account, $product_item, 
$responsibility, $service, $building, $project, $text, $client_ref, $counter)
+               {
+
+                       //$order_id = $order_id + 39500000;
+                       // XXX: Which charsets do Agresso accept/expect? Do we 
need to something regarding padding and UTF-8?
+                       //$order = array();
+
+                       $item_counter    = $counter;
+                       $order                   = array(
+                               'account'                                => 
$account,
+                               'client_ref'                     => $client_ref,
+                               'header'                                 => 
utf8_decode($header),
+                               'bill_year'                              => 
$bill_year,
+                               'bill_month'                     => $bill_month,
+                               'Ansvar'                                 => 
'BKBPE',
+                               'Ansvar2'                                => 
'BKBPE',
+                               'Party'                                  => 
$party_id,
+                               'name'                                   => 
$party_name,
+                               'amount'                                 => 
$this->get_formatted_amount_excel($product_item['amount']),
 //                        'amount' => 
$this->get_formatted_amount($product_items[0]['amount']),
-            'article description' => 
utf8_decode($product_item['article_description']),
-            'article_code' => $product_item['article_code'],
-            'batch_id' => "BKBPE{$this->date_str}",
-            'client' => 'BY',
-            'responsibility' => $responsibility,
-            'service' => $service,
-            'project' => $project,
-            'counter' => ++$item_counter,
-            'bill_year' => $bill_year,
-            'bill_month' => $bill_month,
-            'batch_id' => "BKBPE{$this->date_str}",
-            'client' => 'BY',
-            'item_counter' => $item_counter,
-            'text' => utf8_decode($text)
-            );
-               
-               return str_replace(array("\n", "\r"), '', $order);
-       }
-       
-       protected function get_formatted_amount($amount)
-       {
-               $amount = round($amount, 2) * 100;
-               if($amount < 0) // Negative number
+                               'article description'    => 
utf8_decode($product_item['article_description']),
+                               'article_code'                   => 
$product_item['article_code'],
+                               'batch_id'                               => 
"BKBPE{$this->date_str}",
+                               'client'                                 => 
'BY',
+                               'responsibility'                 => 
$responsibility,
+                               'service'                                => 
$service,
+                               'project'                                => 
$project,
+                               'counter'                                => 
++$item_counter,
+                               'bill_year'                              => 
$bill_year,
+                               'bill_month'                     => $bill_month,
+                               'batch_id'                               => 
"BKBPE{$this->date_str}",
+                               'client'                                 => 
'BY',
+                               'item_counter'                   => 
$item_counter,
+                               'text'                                   => 
utf8_decode($text)
+                       );
+
+                       return str_replace(array("\n", "\r"), '', $order);
+               }
+
+               protected function get_formatted_amount($amount)
                {
-                       return '-' . sprintf("%016.16s", abs($amount)); // We 
have to have the sign at the start of the string
+                       $amount = round($amount, 2) * 100;
+                       if($amount < 0) // Negative number
+                       {
+                               return '-' . sprintf("%016.16s", abs($amount)); 
// We have to have the sign at the start of the string
+                       }
+                       return sprintf("%017.17s", $amount);
                }
-               return sprintf("%017.17s", $amount);
-       } 
-        
-        protected function get_formatted_amount_excel($amount)
-       {
+
+               protected function get_formatted_amount_excel($amount)
+               {
 //            var_dump($amount);
-            
 //            var_dump($belop);
-               $amount = round($amount, 2) * 100;
-                $belop = substr($amount, 0, strlen($amount)-2) . '.' . 
substr($amount, -2);
-               if($amount < 0) // Negative number
-               {
-                       return '-' . sprintf("%016.16s", abs($belop)); // We 
have to have the sign at the start of the string
+                       $amount  = round($amount, 2) * 100;
+                       $belop   = substr($amount, 0, strlen($amount) - 2) . 
'.' . substr($amount, -2);
+                       if($amount < 0) // Negative number
+                       {
+                               return '-' . sprintf("%016.16s", abs($belop)); 
// We have to have the sign at the start of the string
+                       }
+                       return sprintf("%017.17s", $belop);
                }
-               return sprintf("%017.17s", $belop);
-       } 
-       
-} 
 
-?>
\ No newline at end of file
+       }       
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]