Beispiel #1
0
 static function disposal($assetid, $data, &$errors)
 {
     $asset = DataObjectFactory::Factory('Asset');
     if ($asset->load($assetid)) {
         $asset->disposal_date = $data['disposal_date'];
         $asset->disposal_value = $data['disposal_value'];
         if ($asset->save()) {
             unset($data['id']);
             $gltrans = array();
             $gltrans = GLTransaction::makeFromAsset($asset, $asset->purchase_price, 'disposal', $errors);
             if (count($errors) === 0 && count($gltrans) > 0) {
                 $gltrans = array_merge($gltrans, GLTransaction::makeFromAsset($asset, $asset->td_depn, 'disposal-depreciation', $errors));
             }
             if (count($errors) === 0 && count($gltrans) > 0) {
                 $data['armaster_id'] = $asset->id;
                 $data['value'] = $data['disposal_value'];
                 $data['transaction_date'] = $data['disposal_date'];
                 $data['from_group_id'] = $asset->argroup_id;
                 $data['from_location_id'] = $asset->arlocation_id;
                 $artransaction = DataObjectFactory::Factory('ARTransaction');
                 $artransaction = $artransaction->add($data, $artransaction->disposal(), $errors);
                 $result = false;
                 if ($artransaction && count($errors) === 0) {
                     $result = $artransaction->save();
                 }
                 if ($result) {
                     $gltrans = array_merge($gltrans, GLTransaction::makeFromAssetTransaction($artransaction, $asset, $errors));
                 }
                 if ($result === FALSE || count($errors) > 0 || GLTransaction::saveTransactions($gltrans, $errors) === FALSE) {
                     $errors[] = 'Failed to create GL entry for asset disposal';
                 }
             }
         } else {
             $errors[] = 'Failed to update asset disposal date';
         }
     } else {
         $errors[] = 'Failed to load asset';
     }
 }