Ejemplo n.º 1
0
 /**
  * Return true if the given line intersect/overlap
  *
  * @param Line $line
  * @return bool
  */
 public function isOverlap(Line $line)
 {
     $nvA = $this->getNormalVector();
     $nvB = $line->getNormalVector();
     // line equation 1
     $a1 = $nvA->getX();
     $b1 = $nvA->getY();
     $c1 = $nvA->getX() * $this->a->getX() + $nvA->getY() * $this->a->getY();
     // line equation 2
     $a2 = $nvB->getX();
     $b2 = $nvB->getY();
     $c2 = $nvB->getX() * $line->a->getX() + $nvB->getY() * $line->a->getY();
     // Calculation cheat: http://www.thelearningpoint.net/computer-science/c-program-solving-simultaneous-equations-in-two-variables
     if ($a1 * $b2 - $a2 * $b1 != 0 && $b1 * $a2 - $b2 * $a1 != 0) {
         // we have a unique solution
         $x = ($c1 * $b2 - $c2 * $b1) / ($a1 * $b2 - $a2 * $b1);
         $y = ($c1 * $a2 - $c2 * $a1) / ($b1 * $a2 - $b2 * $a1);
         // they intersect so let's check if that intersection point is on the line section
         return $this->hasPoint(new Point($x, $y));
     } elseif ($a1 * $b2 - $a2 * $b1 == 0 && $b1 * $a2 - $b2 * $a1 == 0 && $c1 * $b2 - $c2 * $b1 == 0 && $c1 * $a2 - $c2 * $a1 == 0) {
         // infinite solutions
         return true;
     }
     // no solution: the lines don't intersect each other
     return false;
 }
Ejemplo n.º 2
0
 /**
  * format() should return string if format is html
  */
 public function testFormat_returnsString_ifFormatIsText()
 {
     $word = new Line();
     $expected = "\n";
     $actual = $word->format('text');
     $this->assertEquals($expected, $actual);
     return;
 }
Ejemplo n.º 3
0
 /**
  * Set the tag name.
  *
  * This will also be persisted to the upsteam line and annotation.
  *
  * @param string $name
  */
 public function setName($name)
 {
     $current = $this->getName();
     if ('other' === $current) {
         throw new \RuntimeException('Cannot set name on unknown tag');
     }
     $this->line->setContent(preg_replace("/@{$current}/", "@{$name}", $this->line->getContent(), 1));
     $this->name = $name;
 }
Ejemplo n.º 4
0
 protected function validateLine($line)
 {
     if (!$line instanceof Line) {
         $line = new Line((string) $line);
     }
     if ($line->getLength() != $this->getWidth()) {
         throw new \InvalidArgumentException(sprintf('All lines in a batch file must be %d chars wide this line is %d chars wide.', $this->getWidth(), strlen($line)));
     }
     return $line;
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider dataProviderTestDefine
  */
 public function testDefine($string, $isDefine, $getDefineKey, $getDefineWord)
 {
     $line = new Line($string);
     $this->assertSame($isDefine, $line->isDefine());
     $this->assertSame($getDefineKey, $line->getDefineKey());
     if (is_null($getDefineWord)) {
         $this->assertNull($line->getDefineWord());
     } else {
         $word = $line->getDefineWord();
         $this->assertInstanceOf('\\Inml\\Text\\Word', $word);
         $this->assertSame($getDefineWord, $word->getWord());
     }
 }
Ejemplo n.º 6
0
function addToCart($itemId, $itemName, $qtty, $price, $itemCode, $remarks)
{
    $cart = $_SESSION['cart'];
    $line = new Line();
    if (!isset($cart)) {
        $line->addNewLine(1, $itemId, $itemName, $qtty, $price, $itemCode, $remarks);
        $_SESSION['cart'][1] = $line;
        return;
    }
    $pos = count($_SESSION['cart']) + 1;
    $line->addNewLine($pos, $itemId, $itemName, $qtty, $price, $itemCode, $remarks);
    $_SESSION['cart'][$pos] = $line;
    return;
}
Ejemplo n.º 7
0
 /**
  * Show the prompt to user and return the answer.
  *
  * @return mixed
  */
 public function show()
 {
     /**
      * Ask for a number and validate it.
      */
     do {
         $valid = true;
         $number = parent::show();
         if ($number === "" && !$this->allowEmpty) {
             $valid = false;
         } elseif ($number === "") {
             $number = null;
         } elseif (!is_numeric($number)) {
             $this->getConsole()->writeLine("{$number} is not a number\n");
             $valid = false;
         } elseif (!$this->allowFloat && round($number) != $number) {
             $this->getConsole()->writeLine("Please enter a non-floating number, i.e. " . round($number) . "\n");
             $valid = false;
         } elseif ($this->max !== null && $number > $this->max) {
             $this->getConsole()->writeLine("Please enter a number not greater than " . $this->max . "\n");
             $valid = false;
         } elseif ($this->min !== null && $number < $this->min) {
             $this->getConsole()->writeLine("Please enter a number not smaller than " . $this->min . "\n");
             $valid = false;
         }
     } while (!$valid);
     /**
      * Cast proper type
      */
     if ($number !== null) {
         $number = $this->allowFloat ? (double) $number : (int) $number;
     }
     return $this->lastResponse = $number;
 }
Ejemplo n.º 8
0
 public function apply($resource)
 {
     // Extract arguments
     @(list(, $direction, $step, $thickness, $color) = func_get_args());
     $step = (int) $step;
     $thickness = (int) $thickness;
     if ($step < 2) {
         $step = 2;
     }
     // Get resolution
     $width = imagesx($resource);
     $height = imagesy($resource);
     if ($width === false || $height === false) {
         throw new Exception("An error was encountered while getting image resolution");
     }
     // Apply effect
     switch ($direction) {
         case self::VERTICAL:
             $x = 0;
             while (($x += $step) < $width) {
                 parent::apply($resource, $x, 0, $x, $height, $thickness, $color);
             }
             break;
         case self::HORIZONTAL:
         default:
             $y = 0;
             while (($y += $step) < $height) {
                 parent::apply($resource, 0, $y, $width, $y, $thickness, $color);
             }
     }
     return $resource;
 }
Ejemplo n.º 9
0
 protected function getVector()
 {
     $angle = $this->line->getAngle();
     // Compute paddings
     $vector = new awVector($this->line->p1->move(cos($angle) * $this->padding->left, -1 * sin($angle) * $this->padding->left), $this->line->p2->move(-1 * cos($angle) * $this->padding->right, -1 * -1 * sin($angle) * $this->padding->right));
     return $vector;
 }
Ejemplo n.º 10
0
 protected function validate($value)
 {
     parent::validate($value);
     if (!preg_match("/[a-zA-Z0-9\\-]/is", $value)) {
         throw new Exception\InvalidValue("A name can only contain letters, numbers and the characters '-' and '_'!");
     }
 }
Ejemplo n.º 11
0
    	static function drawGraph($obj=NULL,$parent=NULL)
	{
        $link = $GLOBALS['GRAPHITE_URL'].'/render/?';
        $lines = Line::findAll($obj->getGraphId());
        foreach($lines as $line) {
           $link .= 'target=';
           $target =  'alias(' . $line->getTarget() . '%2C%22' . $line->getAlias() . '%22)';
           if ($line->getColor() != '') {
             $target = 'color(' . $target . '%2C%22' . $line->getColor() . '%22)';
           }
           $link .= $target .'&';
        }
        if (!is_null($parent)) {
          $link .= 'width=' . $parent->getGraphWidth() .'&';
          $link .= 'height=' . $parent->getGraphHeight() .'&';
          if ($obj->getVtitle() != '') {
              $link .= 'vtitle=' . $obj->getVtitle() .'&';
          }
          if ($obj->getName() != '') {
              $link .= 'title=' . $obj->getName() .'&';
          }
          if ($obj->getArea() != 'none') {
              $link .= 'areaMode=' . $obj->getArea() .'&';
          }
          if ($obj->getTime_Value() != '' && $obj->getUnit() != '') {
              $link .= 'from=-' . $obj->getTime_Value() . $obj->getUnit() . '&';
          }
          if ($obj->getCustom_Opts() != '') {
              $link .= $obj->getCustom_Opts() . '&';
          }
        }
       return $link;
	}
Ejemplo n.º 12
0
 /**
  * @param LineBuffer $buffer
  * @param int $indent
  * @param string $firstPrefix
  */
 public function addBuffer(LineBuffer $buffer, $indent = 0, $firstPrefix = '')
 {
     $first = true;
     foreach ($buffer->getLines() as $line) {
         $newline = null;
         if ($first) {
             $first = false;
             $newline = new Line($line->hasMatched(), $firstPrefix . $line->getText(), $line->getMarker());
             $newline->setExtraIndent(max(0, $indent - strlen($firstPrefix)));
         } else {
             $newline = $line;
             $newline->setExtraIndent($indent);
         }
         $this->lines[] = $newline;
     }
 }
Ejemplo n.º 13
0
 public function apply($resource)
 {
     // Get arguments
     @(list(, $thickness, $color, $sides) = func_get_args());
     $thickness = (int) $thickness;
     if (!$color) {
         $color = '#000000';
     }
     $sides = (int) $sides;
     // Get resolution
     $width = imagesx($resource);
     $height = imagesy($resource);
     if ($width === false || $height === false) {
         throw new Exception("An error was encountered while getting image resolution");
     }
     // Define adjustment
     $z = $thickness / 2;
     // Draw borders
     if ($sides == self::ALL || $sides == self::TOP) {
         parent::apply($resource, 0, $z, $width, $z, $thickness, $color);
     }
     if ($sides == self::ALL || $sides == self::RIGHT) {
         parent::apply($resource, $width - $z, $z, $width - $z, $height, $thickness, $color);
     }
     if ($sides == self::ALL || $sides == self::BOTTOM) {
         parent::apply($resource, $width - $z, $height - $z, 0, $height - $z, $thickness, $color);
     }
     if ($sides == self::ALL || $sides == self::LEFT) {
         parent::apply($resource, $z, $height, $z, 0, $thickness, $color);
     }
     return $resource;
 }
Ejemplo n.º 14
0
 /**
  * @inheritDoc
  */
 public function merge($base, $remote, $local)
 {
     // Skip merging if there is nothing to do.
     if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
         return $merged;
     }
     // First try the built in xdiff_string_merge3.
     $merged = xdiff_string_merge3($base, $remote, $local, $error);
     //        if ($error) {
     //            // Try it the other way around.
     //            $error = null;
     //            $merged = xdiff_string_merge3($base, $local, $remote, $error);
     //        }
     if ($error) {
         // So there might be a merge conflict.
         $baseLines = $this->base = Line::createArray(array_map(function ($l) {
             return [$l, 0];
         }, explode("\n", $base)));
         // Get patch strings and transform them to Hunks.
         $remotePatch = xdiff_string_diff($base, $remote, 0);
         $localPatch = xdiff_string_diff($base, $local, 0);
         // Note that patching $remote with $localPatch will work only in
         // some cases because xdiff patches differently than git and will
         // apply the same change twice.
         $remote_hunks = self::interpretDiff($remotePatch);
         $local_hunks = self::interpretDiff($localPatch);
         // Merge Hunks and detect conflicts the same way PhpMerge does.
         $conflicts = [];
         $merged = PhpMerge::mergeHunks($baseLines, $remote_hunks, $local_hunks, $conflicts);
         if ($conflicts) {
             throw new MergeException('A merge conflict has occured.', $conflicts, $merged);
         }
     }
     return $merged;
 }
Ejemplo n.º 15
0
 /**
  * Set element property by name
  * @param string $name
  * @param mixed $value
  * @return boolean
  */
 public function setProperty($name, $value)
 {
     $name = strtolower($name);
     $value = trim($value);
     switch ($name) {
         case 'fill':
             if ($value === true || array_search($value, self::$fill_true) !== false) {
                 $this->properties['fill'] = true;
                 return true;
             } elseif ($value == false || array_search($value, self::$fill_false) !== false) {
                 $this->properties['fill'] = false;
                 $this->unsetProperty('fillcolor');
                 $this->unsetProperty('fillopacity');
                 return true;
             } else {
                 $this->errormessages[] = \wfMessage('multimaps-element-illegal-value', $name, $value, '"' . implode('", "', self::getPropertyValidValues($name)) . '"')->escaped();
                 return false;
             }
             break;
         case 'fillcolor':
         case 'fillopacity':
             $this->fill = true;
             return parent::setProperty($name, $value);
             break;
         default:
             return parent::setProperty($name, $value);
             break;
     }
 }
Ejemplo n.º 16
0
 /**
  * Tokenize a line
  *
  * @param  net.daringfireball.markdown.Line $l The line
  * @param  net.daringfireball.markdown.Node $target The target node to add nodes to
  * @return net.daringfireball.markdown.Node The target
  */
 public function tokenize(Line $line, Node $target)
 {
     $safe = 0;
     $l = $line->length();
     while ($line->pos() < $l) {
         $t = '';
         $c = $line->chr();
         if ('\\' === $c) {
             $t = $line[$line->pos() + 1];
             $line->forward(2);
             // Skip escape, don't tokenize next character
         } else {
             if (isset($this->tokens[$c])) {
                 if (!$this->tokens[$c]($line, $target, $this)) {
                     $t = $c;
                     // Push back
                     $line->forward();
                 }
             }
         }
         // Optimization: Do not create empty text nodes
         if ('' !== ($t .= $line->until($this->span))) {
             $target->add(new Text($t));
         }
         if ($safe++ > $l) {
             throw new \lang\IllegalStateException('Endless loop detected');
         }
     }
     return $target;
 }
Ejemplo n.º 17
0
 /**
  * Creates a new conflicted line
  * @param string $base        The line as present in the base branch
  * @param string $head        The line as present in the head branch
  * @param type   $branch_name The name of the head branch
  */
 public function __construct($base, $head, $branch_name = '')
 {
     $this->base = $base;
     $this->head = $head;
     $line = '<<<<<<< HEAD' . "\n";
     $line .= $base . "\n";
     $line .= '=======' . "\n";
     $line .= $head . "\n";
     $line .= '>>>>>>> ' . $branch_name;
     parent::__construct($line, parent::BOTH);
 }
 /**
  * checks is word repeatable at different lines
  * @param Line $line - each line object
  * @return boolean
  */
 private function CheckIsAllWordsRepeateableAtLines(Line $line)
 {
     $temp_words = array();
     foreach ($this->repeatableWordsInfo as $key => $value) {
         $temp_words[] = $key;
     }
     $flag = 0;
     $amount = count($temp_words);
     foreach ($line->GetRepeatableWords() as $word) {
         foreach ($temp_words as $item) {
             if ($item == $word->GetContent()) {
                 $flag++;
             }
         }
     }
     if ($flag != $amount) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 19
0
 /**
  * Constructor
  *
  * @param string $string String to parse
  */
 public function __construct($string)
 {
     $this->rawString = $string;
     $parts = explode(Line::SEPARATOR, $string);
     foreach ($parts as $item) {
         $line = new Line($item);
         if ($line->isStyle()) {
             $this->styles = array_merge($this->styles, $line->getStyles());
         } elseif ($line->isDefine()) {
             $this->defines[$line->getDefineKey()] = $line->getDefineWord();
         } elseif (!$line->isEmpty()) {
             $this->lines[] = $line;
         }
     }
 }
Ejemplo n.º 20
0
 public static function cloneLine($line_id, $ignore_clone_name = FALSE, $graph_id = NULL)
 {
     $line_to_clone = new Line($line_id);
     if (empty($graph_id)) {
         $graph_id = $line_to_clone->getGraphId();
     }
     $line = new Line();
     if ($ignore_clone_name) {
         $clone_alias = $line_to_clone->getAlias();
     } else {
         $clone_alias = 'Clone of ' . $line_to_clone->getAlias();
         // If it's too long, we truncate
         if (strlen($clone_alias) > 255) {
             $clone_alias = substr($clone_alias, 0, 255);
         }
     }
     $line->setAlias($clone_alias);
     $line->setTarget($line_to_clone->getTarget());
     $line->setColor($line_to_clone->getColor());
     $line->setGraphId($graph_id);
     $line->setWeight($line_to_clone->getWeight());
     $line->store();
 }
Ejemplo n.º 21
0
 public function display()
 {
     parent::display();
     // TODO: Change the autogenerated stub
     echo "x3=" . $this->x3 . "</br>";
     echo "y3=" . $this->y3 . "</br>";
 }
 /**
  * Get the line type
  *
  * @return NULL
  */
 function getLegendLineStyle()
 {
     return $this->line->getStyle();
 }
Ejemplo n.º 23
0
 private function drawFilledTriangleHorizontally(awGradient $gradient, awPolygon $polygon)
 {
     list($xMin, $xMax) = $polygon->getBoxXRange();
     $this->init($gradient, $xMax - $xMin);
     // Get the triangle line we will draw our lines from
     $fromLine = NULL;
     $lines = $polygon->getLines();
     $count = count($lines);
     // Pick the side of the triangle going all the way
     // from the left side to the right side of the surrounding box
     for ($i = 0; $i < $count; $i++) {
         if ($lines[$i]->isLeftToRight($polygon)) {
             list($fromLine) = array_splice($lines, $i, 1);
             break;
         }
     }
     // If for some reason the three points are aligned,
     // $fromLine will still be NULL
     if ($fromLine === NULL) {
         return;
     }
     $fillLine = NULL;
     for ($x = round($xMin); $x < round($xMax); $x++) {
         $fromY = floor($fromLine->getYFrom($x));
         $toY = array();
         foreach ($lines as $line) {
             $yValue = $line->getYFrom($x);
             if (!is_null($yValue)) {
                 $toY[] = floor($yValue);
             }
         }
         if (count($toY) === 1) {
             $fillLine = new Line(new Point($x, $fromY), new Point($x, $toY[0]));
         } else {
             $line1 = new Line(new Point($x, $fromY), new Point($x, $toY[0]));
             $line2 = new Line(new Point($x, $fromY), new Point($x, $toY[1]));
             if ($line1->getSize() < $line2->getSize()) {
                 $fillLine = $line1;
             } else {
                 $fillLine = $line2;
             }
         }
         $color = $this->color($x - $xMin);
         if ($fillLine->isPoint()) {
             $this->driver->point($color, $fillLine->p1);
         } elseif ($fillLine->getSize() >= 1) {
             $this->driver->line($color, $fillLine);
         }
         unset($color);
     }
 }
Ejemplo n.º 24
0
 /**
  * Draw a colored rectangle
  *
  * @param $color Rectangle color
  * @param $line Rectangle diagonale
  * @param $p2
  */
 function rectangle($color, $line)
 {
     list($p1, $p2) = $line->getLocation();
     // Get Red, Green, Blue and Alpha values for the line
     list($r, $g, $b, $a) = $this->getColor($color);
     // Calculate the coordinates of the two other points of the rectangle
     $p3 = new Point($p1->x, $p2->y);
     $p4 = new Point($p2->x, $p1->y);
     $side = new Line($p1, $p2);
     // Draw the four sides of the rectangle, clockwise
     if ($p1->x <= $p2->x and $p1->y <= $p2->y or $p1->x >= $p2->x and $p1->y >= $p2->y) {
         $side->setLocation($p1, $p4);
         $this->line($color, $side);
         $side->setLocation($p4, $p2);
         $this->line($color, $side);
         $side->setLocation($p2, $p3);
         $this->line($color, $side);
         $side->setLocation($p3, $p1);
         $this->line($color, $side);
     } else {
         $side->setLocation($p1, $p3);
         $this->line($color, $side);
         $side->setLocation($p3, $p2);
         $this->line($color, $side);
         $side->setLocation($p2, $p4);
         $this->line($color, $side);
         $side->setLocation($p4, $p1);
         $this->line($color, $side);
     }
 }
Ejemplo n.º 25
0
 public function postLineEdit($LineId)
 {
     $rules = array('name' => 'required|min:2|unique:line,name,' . $LineId, 'code' => 'required|unique:line,code,' . $LineId);
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('branch/line-edit/' . $LineId)->withErrors($validator)->withInput();
     }
     $line = Line::find($LineId);
     $line->name = Input::get('name');
     $line->code = Input::get('code');
     $line->save();
     return Redirect::to('branch/line')->with('success', '线路更新成功!');
 }
Ejemplo n.º 26
0
 function createStandardRequest($calc, $products, $sign = 1)
 {
     if (!class_exists('TaxServiceSoap')) {
         require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php';
     }
     if (!class_exists('DocumentType')) {
         require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php';
     }
     if (!class_exists('DetailLevel')) {
         require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php';
     }
     if (!class_exists('Line')) {
         require VMAVALARA_CLASS_PATH . DS . 'Line.class.php';
     }
     if (!class_exists('ServiceMode')) {
         require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php';
     }
     if (!class_exists('Line')) {
         require VMAVALARA_CLASS_PATH . DS . 'Line.class.php';
     }
     if (!class_exists('GetTaxRequest')) {
         require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php';
     }
     if (!class_exists('GetTaxResult')) {
         require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php';
     }
     if (!class_exists('Address')) {
         require VMAVALARA_CLASS_PATH . DS . 'Address.class.php';
     }
     if (is_object($calc)) {
         $calc = get_object_vars($calc);
     }
     $request = new GetTaxRequest();
     $origin = new Address();
     //In Virtuemart we have not differenct warehouses, but we have a shipment address
     //So when the vendor has a shipment address, we assume that it is his warehouse
     //Later we can combine products with shipment addresses for different warehouse (yehye, future music)
     //But for now we just use the BT address
     if (!class_exists('VirtueMartModelVendor')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php';
     }
     $userId = VirtueMartModelVendor::getUserIdByVendorId($calc['virtuemart_vendor_id']);
     $userModel = VmModel::getModel('user');
     $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId);
     // this is needed to set the correct user id for the vendor when the user is logged
     $userModel->getVendor($calc['virtuemart_vendor_id']);
     $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE);
     $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id];
     $origin->setLine1($vendorFields['fields']['address_1']['value']);
     $origin->setLine2($vendorFields['fields']['address_2']['value']);
     $origin->setCity($vendorFields['fields']['city']['value']);
     $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']);
     $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']);
     $origin->setPostalCode($vendorFields['fields']['zip']['value']);
     $request->setOriginAddress($origin);
     //Address
     if (isset($this->addresses[0])) {
         $destination = $this->addresses[0];
     } else {
         return FALSE;
     }
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $request->setCurrencyCode($calculator->_currencyDisplay->_vendorCurrency_code_3);
     //CurrencyCode
     $request->setDestinationAddress($destination);
     //Address
     $request->setCompanyCode($calc['company_code']);
     // Your Company Code From the Dashboard
     $request->setDocDate(date('Y-m-d'));
     //date, checked
     $request->setCustomerCode(self::$vmadd['customer_number']);
     //string Required
     if (isset(self::$vmadd['tax_usage_type'])) {
         $request->setCustomerUsageType(self::$vmadd['tax_usage_type']);
         //string   Entity Usage
     }
     if (isset(self::$vmadd['tax_exemption_number'])) {
         $request->setExemptionNo(self::$vmadd['tax_exemption_number']);
         //string   if not using ECMS which keys on customer code
     }
     if (isset(self::$vmadd['taxOverride'])) {
         $request->setTaxOverride(self::$vmadd['taxOverride']);
         avadebug('I set tax override ', self::$vmadd['taxOverride']);
     }
     $setAllDiscounted = false;
     if (isset($products['discountAmount'])) {
         if (!empty($products['discountAmount'])) {
             //$request->setDiscount($sign * $products['discountAmount'] * (-1));            //decimal
             $request->setDiscount($sign * $products['discountAmount']);
             //decimal
             vmdebug('We sent as discount ' . $request->getDiscount());
             $setAllDiscounted = true;
         }
         unset($products['discountAmount']);
     }
     $request->setDetailLevel('Tax');
     //Summary or Document or Line or Tax or Diagnostic
     $lines = array();
     $n = 0;
     $this->_lineNumbersToCartProductId = array();
     foreach ($products as $k => $product) {
         $n++;
         $this->_lineNumbersToCartProductId[$n] = $k;
         $line = new Line();
         $line->setNo($n);
         //string  // line Number of invoice
         $line->setItemCode($product['product_sku']);
         //string
         $line->setDescription($product['product_name']);
         //product description, like in cart, atm only the name, todo add customfields
         if (!empty($product['categories'])) {
             //avadebug('AvaTax setTaxCode Product has categories !',$catNames);
             if (!class_exists('TableCategories')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'categories.php';
             }
             $db = JFactory::getDbo();
             $catTable = new TableCategories($db);
             foreach ($product['categories'] as $cat) {
                 $catTable->load($cat);
                 $catslug = $catTable->slug;
                 if (strpos($catslug, 'avatax-') !== FALSE) {
                     $taxCode = substr($catslug, 7);
                     if (!empty($taxCode)) {
                         $line->setTaxCode($taxCode);
                     } else {
                         vmError('AvaTax setTaxCode, category could not be parsed ' . $catslug);
                     }
                     break;
                 }
             }
         }
         //$line->setTaxCode("");             //string
         $line->setQty($product['amount']);
         //decimal
         $line->setAmount($sign * $product['price'] * $product['amount']);
         //decimal // TotalAmmount
         if ($setAllDiscounted or !empty($product['discount'])) {
             $line->setDiscounted(1);
         } else {
             $line->setDiscounted(0);
         }
         $line->setRevAcct("");
         //string
         $line->setRef1("");
         //string
         $line->setRef2("");
         //string
         if (isset(self::$vmadd['tax_usage_type'])) {
             $line->setCustomerUsageType(self::$vmadd['tax_usage_type']);
             //string   Entity Usage
         }
         if (isset(self::$vmadd['tax_exemption_number'])) {
             $line->setExemptionNo(self::$vmadd['tax_exemption_number']);
             //string   if not using ECMS which keys on customer code
         }
         if (isset(self::$vmadd['taxOverride'])) {
             //create new TaxOverride Object set
             //$line->setTaxOverride(self::$vmadd['taxOverride']);
         }
         $lines[] = $line;
     }
     $this->newATConfig($calc);
     $request->setLines($lines);
     return $request;
 }
Ejemplo n.º 27
0
 /**
  * Makes a Line object from a product item object
  *
  * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
  * @param bool $credit
  * @return null
  */
 protected function _newLine($item, $credit = false)
 {
     if ($this->isProductCalculated($item->getOrderItem())) {
         return false;
     }
     if ($item->getQty() == 0) {
         return false;
     }
     $line = new Line();
     $storeId = $this->_retrieveStoreIdFromItem($item);
     $price = $item->getBaseRowTotal();
     if ($this->_getTaxDataHelper()->priceIncludesTax($storeId)) {
         $line->setTaxIncluded(true);
         $price = $item->getBaseRowTotalInclTax();
     }
     if ($this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId)) {
         $price -= $item->getBaseDiscountAmount();
     }
     if ($credit) {
         //@startSkipCommitHooks
         $price *= -1;
         //@finishSkipCommitHooks
     }
     $line->setNo(count($this->_lines));
     $line->setItemCode($this->_getCalculationHelper()->getItemCode($this->_getProductForItemCode($item), $storeId, $item));
     $line->setDescription($item->getName());
     $line->setQty($item->getQty());
     $line->setAmount($price);
     $line->setDiscounted((double) $item->getBaseDiscountAmount() && $this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId));
     $productData = $this->_getLineProductData($item, $storeId);
     $line->setTaxCode($productData->getTaxCode());
     $line->setRef1($productData->getRef1());
     $line->setRef2($productData->getRef2());
     $this->_lineToItemId[count($this->_lines)] = $item->getOrderItemId();
     $this->_lines[] = $line;
 }
 /**
  * @param Line $line
  * @return VTrendLines
  */
 public function addLine(Line $line)
 {
     $this->lines[] = $line->getXML();
     return $this;
 }
Ejemplo n.º 29
0
        </thead>
        <tbody>
            <?php 
$first = TRUE;
if ($filter_group_id == -1) {
    $dashboards = Dashboard::findAll();
} else {
    $dashboards = Dashboard::findAllByFilter($filter_group_id);
}
/* Filter Graphs */
foreach ($dashboards as $dashboard) {
    $dashboard_id = $dashboard->getDashboardId();
    $graphs = Graph::findAll($dashboard_id);
    $number_of_lines = 0;
    foreach ($graphs as $graph) {
        $number_of_lines = $number_of_lines + Line::countAllByFilter($graph->getGraphId(), $filter_text);
    }
    $number_of_graphs = Graph::countAllByFilter($dashboard_id, $filter_text);
    ?>
            <?php 
    if ($number_of_graphs > 0 || $number_of_lines > 0 || preg_match('/' . $filter_text . '/i', $dashboard->getName()) || preg_match('/' . $filter_text . '/i', $dashboard->getDescription())) {
        ?>
 
                <tr>
                    <td class="name">
                        <a href="<?php 
        echo Dashboard::makeURL('view', $dashboard);
        ?>
">
                            <?php 
        if ($dashboard->getName()) {
Ejemplo n.º 30
0
        // 3 -> Both are displayed
        $display_options_links = 0;
    }
    include VIEW_PATH . '/view_dashboard.php';
} elseif ('delete' == $action) {
    $class_name = 'Dashboard';
    try {
        $obj = new Dashboard($dashboard_id);
        $delete_text = 'Are you sure you want to delete dashboard : <strong>' . $obj->getName() . '</strong>?';
        if (fRequest::isPost()) {
            fRequest::validateCSRFToken(fRequest::get('token'));
            $obj->delete();
            $graphs = Graph::findAll($dashboard_id);
            // Do Dashboard Subelement Cleanup
            foreach ($graphs as $graph) {
                $lines = Line::findAll($graph->getGraphId());
                foreach ($lines as $line) {
                    $line->delete();
                }
                $graph->delete();
            }
            fMessaging::create('success', Dashboard::makeUrl('list'), 'The Dashboard ' . $obj->getName() . ' was successfully deleted');
            fURL::redirect(Dashboard::makeUrl('list'));
        }
    } catch (fNotFoundException $e) {
        fMessaging::create('error', Dashboard::makeUrl('list'), 'The Dashboard requested could not be found');
        fURL::redirect(Dashboard::makeUrl('list'));
    } catch (fExpectedException $e) {
        fMessaging::create('error', fURL::get(), $e->getMessage());
    }
    include VIEW_PATH . '/delete.php';