function TaxRatesTranslator_main()
{
    $obj = new TaxRatesTranslator(empty($_POST['input']) ? "abc" : $_POST['input']);
    $obj->parse();
    $TaxArray = $obj->getTaxList();
    echo "\n<br>";
    print_r($TaxArray);
}
예제 #2
0
 function isTaxFormulaSetCyclic($tax_name_id__to__formula, $source_tax_name_id)
 {
     loadCoreFile('tax_formula_translator.php');
     //VIII.1.( 6)
     //Create a graph. Vertexes are $tax_name_id. Arcs are directed relations
     //  between vertexes, taken from tax-formulae.
     $tax_names = modApiFunc("Taxes", "getTaxNamesList");
     //Graph vertex:
     $V = array();
     //Graph arcs:
     $ADJ = array();
     $ADJinfo = array();
     foreach ($tax_names as $tax_name) {
         $V[] = (int) $tax_name["Id"];
         $ADJ[(int) $tax_name["Id"]] = array();
         $ADJinfo[(int) $tax_name["Id"]] = array();
     }
     //Graph arcs:
     //In the graph arcs is stored additional information: which tax formula contains
     //  this arc. It is necessary to show, which formulae the cycle (not arcs)
     //  consists of.
     foreach ($tax_name_id__to__formula as $vertex_id => $vertex_info) {
         //            //Add a vertex, if it still doesn't exist. There should be no
         //            //iterations.
         //            if(!in_array($vertex_id, $V))
         //            {
         //                $V[] = $vertex_id;
         //            }
         //Add all arcs.
         //Parse the formula.
         $trans = new TaxRatesTranslator($vertex_info['formula']);
         $trans->parse();
         $ADJ[$vertex_id] = $trans->getTaxList();
         $ADJinfo[$vertex_id] = array("formula_id" => $vertex_info['formula_id']);
     }
     loadCoreFile('directed_graph.php');
     $graph = new DirectedGraph($V, $ADJ);
     if ($graph->hasCycleFromGivenSource($source_tax_name_id, $cycle)) {
         //It's necessary to restore formulae, which in this case
         // (i.e. depending on state and tax_class) match
         // specified arcs in the graph.
         $cycle_with_tax_info = array();
         //Suppose cycle is correct ring
         $previous_vertex_in_cycle = $cycle[sizeof($cycle) - 1]['tax_name_id'];
         $i = 0;
         for (; $i < sizeof($cycle); $i++) {
             $vertex = $cycle[$i];
             $vertex_with_tax_info = array("tax_name_id" => $vertex, "formula_id" => $ADJinfo[$vertex]['formula_id'], "child_tax_name_id" => $previous_vertex_in_cycle);
             $cycle_with_tax_info[] = $vertex_with_tax_info;
             $previous_vertex_in_cycle = $vertex;
             //formula_id in this case formula_id is a formula id, which
             //is used up to the next vertex in the cycle.
         }
         $cycle = $cycle_with_tax_info;
         return $cycle_with_tax_info;
         //true;
     } else {
         return false;
     }
 }