<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>uid
getResourceUid
getInventoriatedQuantity
getSourceUid
getDestinationUid
getSourceSectionUid
getDestinationSectionUid
isMovement
getSourceTotalAssetPrice
getDestinationTotalAssetPrice</params>
<dtml-let row_list="[]">
  <dtml-in prefix="loop" expr="_.range(_.len(uid))">
    <dtml-if "isMovement[loop_item]">
      <dtml-if "getResourceUid[loop_item]">
        <dtml-if "getDestinationUid[loop_item]">
          <dtml-call expr="row_list.append([uid[loop_item], getDestinationUid[loop_item], getDestinationSectionUid[loop_item], getSourceSectionUid[loop_item], getResourceUid[loop_item], -getInventoriatedQuantity[loop_item], getDestinationTotalAssetPrice[loop_item]])">
        </dtml-if>
        <dtml-if "getSourceUid[loop_item]">
          <dtml-call expr="row_list.append([uid[loop_item], getSourceUid[loop_item], getSourceSectionUid[loop_item], getDestinationSectionUid[loop_item], getResourceUid[loop_item], getInventoriatedQuantity[loop_item], getSourceTotalAssetPrice[loop_item]])">
        </dtml-if>
      </dtml-if>
    </dtml-if>
  </dtml-in>  
  
  <dtml-if "len(row_list) > 0">
INSERT INTO
  stock
VALUES
    <dtml-in prefix="row" expr="row_list">
(
  <dtml-sqlvar expr="row_item[0]" type="int">,
  <dtml-sqlvar expr="row_item[1]" type="int">,  
  <dtml-sqlvar expr="row_item[2]" type="int" optional>, 
  <dtml-sqlvar expr="row_item[3]" type="int" optional>,
  <dtml-sqlvar expr="row_item[4]" type="int">, 
  <dtml-sqlvar expr="row_item[5]" type="float" optional>,
  <dtml-sqlvar expr="row_item[6]" type="float" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
    </dtml-in>
  </dtml-if>
</dtml-let>
