1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
This function retrieves the data.

//    Get data from SQL Server
    protected function _importData() {
        if (!isset($this->SOP10100)) {
            $this->loadModel('SOP10100');
            if (!isset($this->SOP10200)) {
                $this->loadModel('SOP10200');
            }
        }
//      Set data to local variable
        $data = $this->SOP10100->find('all', array(
            'fields' => $this->SOP10100->defaultFields, array(
                'fields' => $this->SOP10200->defaultFields)));

Which in turn calls this function

//      If we have external data, then add the static values to the records
//        if ($data) {
        $this->_prepopulateFields($data);

which in turn manipulates $data like this

    protected function _prepopulateFields($data) {
//        $isCredit = FALSE;

        foreach ($data as $invoices) {
//            debug($invoices);
            foreach ($invoices as $fieldName => $fieldValue) {
                debug(array($fieldName,$fieldValue));
            }
        }
    }  

Output from unmodified $data

\app\Controller\InvoicesController.php (line 91)
array(
  (int) 0 => array(
    'SOP10100' => array(
      'SOPNUMBE' => 'INV253688            ',
      'DOCDATE' => '2011-10-28 00:00:00',
      'DOCAMNT' => '5.40000',
      'SUBTOTAL' => '5.00000'
    ),
    'InvoiceDetail' => array(
      (int) 0 => array(
        'SOPTYPE' => '3',
        'SOPNUMBE' => 'INV253688            ',
        'LNITMSEQ' => '16384',
        'CMPNTSEQ' => '0',
        'ITEMNMBR' => 'BASIC SERVICE                  ',
        'ITEMDESC' => 'BASIC PRODUCTION ENHANCEMENT SERVICE                                                                 ',
        'NONINVEN' => '0',
        'DROPSHIP' => '0',
        'UOFM' => 'EA       ',
        'LOCNCODE' => '01         ',
        'UNITCOST' => '.00000',
        'ORUNTCST' => '.00000',
        'UNITPRCE' => '5.00000',
        'ORUNTPRC' => '5.00000',
        'XTNDPRCE' => '5.00000',
        'OXTNDPRC' => '5.00000',
        'REMPRICE' => '5.00000',
        'OREPRICE' => '5.00000',
        'EXTDCOST' => '.00000',
        'OREXTCST' => '.00000',
        'MRKDNAMT' => '.00000',
        'ORMRKDAM' => '.00000',
        'MRKDNPCT' => '0',
        'MRKDNTYP' => '0',
        'INVINDX' => '14',
        'CSLSINDX' => '10728',
        'SLSINDX' => '10711',
        'MKDNINDX' => '10711',
        'RTNSINDX' => '14',
        'INUSINDX' => '16',
        'INSRINDX' => '10711',
        'DMGDINDX' => '14',
        'ITMTSHID' => '',
        'IVITMTXB' => '3',
        'BKTSLSAM' => '.00000',
        'ORBKTSLS' => '.00000',
        'TAXAMNT' => '.40000',
        'ORTAXAMT' => '.40000',
        'TXBTXAMT' => '.00000',
        'OTAXTAMT' => '.00000',
        'BSIVCTTL' => '0',
        'TRDISAMT' => '.00000',
        'ORTDISAM' => '.00000',
        'DISCSALE' => '.00000',
        'ORDAVSLS' => '.00000',
        'QUANTITY' => '1.00000',
        'ATYALLOC' => '.00000',
        'QTYINSVC' => '.00000',
        'QTYINUSE' => '.00000',
        'QTYDMGED' => '.00000',
        'QTYRTRND' => '.00000',
        'QTYONHND' => '.00000',
        'QTYCANCE' => '.00000',
        'QTYCANOT' => '.00000',
        'QTYONPO' => '.00000',
        'QTYORDER' => '1.00000',
        'QTYPRBAC' => '.00000',
        'QTYPRBOO' => '.00000',
        'QTYPRINV' => '.00000',
        'QTYPRORD' => '.00000',
        'QTYPRVRECVD' => '.00000',
        'QTYRECVD' => '.00000',
        'QTYREMAI' => '1.00000',
        'QTYREMBO' => '.00000',
        'QTYTBAOR' => '.00000',
        'QTYTOINV' => '1.00000',
        'QTYTORDR' => '.00000',
        'QTYFULFI' => '1.00000',
        'QTYSLCTD' => '.00000',
        'QTYBSUOM' => '1.00000',
        'EXTQTYAL' => '.00000',
        'EXTQTYSEL' => '.00000',
        'ReqShipDate' => '2011-10-28 00:00:00',
        'FUFILDAT' => '2011-10-28 00:00:00',
        'ACTLSHIP' => '2011-10-28 00:00:00',
        'SHIPMTHD' => 'DELIVERY       ',
        'SALSTERR' => '',
        'SLPRSNID' => '',
        'PRCLEVEL' => 'CUSTOMER   ',
        'COMMNTID' => '',
        'BRKFLD1' => '0',
        'BRKFLD2' => '0',
        'BRKFLD3' => '0',
        'CURRNIDX' => '1007',
        'TRXSORCE' => '',
        'SOPLNERR' => '00000000',
        'ORGSEQNM' => '0',
        'ITEMCODE' => '',
        'PURCHSTAT' => '1',
        'DECPLQTY' => '1',
        'DECPLCUR' => '3',
        'ODECPLCU' => '3',
        'QTYTOSHP' => '.00000',
        'XFRSHDOC' => '0',
        'EXCEPTIONALDEMAND' => '0',
        'TAXSCHID' => 'SUB_LA 050     ',
        'TXSCHSRC' => '2',
        'PRSTADCD' => 'WK&L #66       ',
        'ShipToName' => 'DUNE ENERGY, INC                                                 ',
        'CNTCPRSN' => '',
        'ADDRESS1' => 'BATEMAN LAKE FIELD                                           ',
        'ADDRESS2' => 'WK&L #66                                                     ',
        'ADDRESS3' => '',
        'CITY' => 'ST MARY                            ',
        'STATE' => 'LA                           ',
        'ZIPCODE' => '',
        'CCode' => '',
        'COUNTRY' => '',
        'PHONE1' => '00000000000000       ',
        'PHONE2' => '00000000000000       ',
        'PHONE3' => '00000000000000       ',
        'FAXNUMBR' => '00000000000000       ',
        'Flags' => '0',
        'BackoutTradeDisc' => '.00000',
        'OrigBackoutTradeDisc' => '.00000',
        'GPSFOINTEGRATIONID' => '',
        'INTEGRATIONSOURCE' => '0',
        'INTEGRATIONID' => '',
        'CONTNBR' => '',
        'CONTLNSEQNBR' => '.00000',
        'CONTSTARTDTE' => '1900-01-01 00:00:00',
        'CONTENDDTE' => '1900-01-01 00:00:00',
        'CONTITEMNBR' => '',
        'CONTSERIALNBR' => '',
        'BULKPICKPRNT' => '0',
        'INDPICKPRNT' => '0',
        'ISLINEINTRA' => '0',
        'SOFULFILLMENTBIN' => '',
        'MULTIPLEBINS' => '0',
        'DEX_ROW_TS' => '2011-10-28 15:42:02',
        'DEX_ROW_ID' => '863815'
      )
    )
  ),